Key idea the divisibilities imply $\,q = a/b\,$ (wlog reduced) can be written in one form where its $\rm\color{#c00}{numerator}$ is a power of $\,p\,$ and another form where its $\rm\color{#0a0}{denominator}$ is a power of $\,p,\,$ hence by $\rm\color{darkorange}{UF}$ = unique fractionization its reduced numerator and denominator are both powers of $\,p,\,$ so $\,q = p^k,\ k\in\Bbb Z,\,$ so $\,q\,$ or $\,1/q\,$ in $\Bbb Z,\,$ i.e. $\,b\mid a\,$ or $\,a\mid b.\,$ More precisely, generalizing we have
$\qquad q=\overbrace{\dfrac{\color{#c00}{p^I}}d =\phantom{a} }^{\textstyle\!\! a\mid p^Ib}\!\!\!\dfrac{a}b\!\!\overbrace{\phantom{a}=\dfrac{c^{\phantom{I}}}{\color{#0a0}{p^J}}}^{\textstyle b\mid ap^J\!\!\!\!\!\!}\,$ $\Rightarrow\, q=\dfrac{\color{#c00}{p^i}}{\color{#0a0}{p^j}}\,\Rightarrow\,\overbrace{q\ \,{\rm or}\,\ \dfrac{1}q\in \Bbb Z}^{\textstyle b\mid a\,\ {\rm or}\,\ a\mid b}\ $ (if $\,i\ge j\,$ or $\,i<j\,$ resp.)
because by $\,\rm\color{darkorange}{UF}$: $\ (a,b)\!=\!1\,\Rightarrow \,a\mid \color{#c00}{p^I}\,$ so $\,a = \color{#c00}{p^i},\,$ and $\,b\mid \color{#0a0}{p^J}\,\Rightarrow\, b = \color{#0a0}{p^j}$
Remark $ $ The proof in your answer is the special case $\,I=1=J\,$ of the above proof. Both proofs use properties of gcds that are equivalent to UPF = uniqueness of prime factorizations, so it would be circular to attempt to use these to prove UPF. The proof in Zhang's answer also implicitly uses a consequence of UPF, that the only divisors of a prime power $\,p^n$ are of the form $\,\pm p^k,\, k\le n.\,$ These properties may fail in domains where UPF fails, i.e. non UFDs.
Proofs like this become clearer when one studies local methods (valuation rings / theory), which helps to algebraically reify the algebraic structure hidden in such divisibility relations.