I have a question regarding a proof in Peter Falb's Methods of Algebraic Geometry in Control Theory, volume I, for the claim in the title.
On pages 16-17 he proves the property (ii) of UFDs that the factorization is unique to within order and unit factors.
The proof goes as follows:
As for property (ii), it is enough to show that if $p(x)$ divides $f(x)g(x)$, then $p(x)$ is a divisor of either $f(x)$ or $g(x)$. If $p(x)$ has degree zero, then $p(x)$ is a divisor of either $c(f)$ or $c(g)$ and hence of either $f(x)$ or $g(x)$. If $p(x)$ has positive degree, then $p(x)$ is primitive. We suppose that $p(x)$ is not a divisor of $f(x)$ and that $f(x)$ has degree $m$. We let $M=R[x]p(x)+R[x]f(x)$. If $a(x)$ is a nonzero element of $M$ of lowest degree $n$ with leading coefficient $\alpha$, then, by lemma 3.5 (Euclidean Algorithm), $\alpha^{m-n+1}f(x)= d(x)a(x)+r(x)$ with $deg \ r(x) <n$ or $r(x)=0$. Since $d(x)a(x)$ and $\alpha^{m-n+1}f(x)$ are in $M$, $r(x)=0$. Let $a(x)=c(a)a_1(x)$ with $a_1(x)$ primitive. In view of corollary 3.4 (If $g(x)$ divides $\alpha f(x)$ with $\alpha \in R$ and $g$ primitive, then $g(x)$ divides $f(x)$.), $a_1(x)$ is a divisor of $f(x)$ and similarly, $a_1(x)$ is a divisor of $p(x)$. Since $p(x)$ is prime and does not divide $f(x)$, $a_1(x)$ is a unit in $R[x]$ and so, is an elemnt of $R$. Hence $a(x) = c(a)a_1\in R$ and $a\in M$ so that $ag(x) = b_1(x)p(x)g(x)+b_2(x)f(x)g(x)$. It follows that $p(x)$ divides $ag(x)$ and by corollary 3.4, that $p(x)$ divides $g(x)$.
I don't understand why does it follow that in the last line $p(x)$ divides $ag(x)$ from what does it follow?
$p(x)|b_1(x)p(x)g(x)$ and by assumption $p(x)|b_2(x)f(x)g(x)$. So $p(x)$ divides sum of them, which is $ag(x).$