Two principal ideals coincide if and only if their generators are associated
This is easily proved true if $\rm\:a,b\:$ are not zero-divisors. It may fail otherwise, e.g. Kaplansky gave this counterexample: in the ring of continuous real functions on $[0,3],$ define piecewise $\rm\:a(t)\:$ and $\rm\:b(t)\:$ as follows: $\rm\: a(t) =1\!-\!t=b(t)\:$ on $[0,1];$ both $\,0\,$ on $[1,2];$ $\rm\:a(t)=t-2 = -b(t)$ on $[2,3].$
Kap remarked that the property is true for Artinian rings, principal ideal rings, and rings whose zero-divisors are contained in the Jacobson radical. For much further analysis see
When are Associates Unit Multiples?
D.D. Anderson, M. Axtell, S.J. Forman, and Joe Stickles
Rocky Mountain J. Math. Volume 34, Number 3 (2004), 811-828.
This is not quite true over arbitrary (commutative) rings, although it holds over integral domains. From the given condition you get elements $u,v$ so that $b=ua$, $a=vb$ and so $b=uvb$ and $a=vua$. When $a$ or $b$ is a regular element, as always happens in an integral domain (with the exception of the trivial case $a=b=0$) then one can cancel it to conclude that $u$ and $v$ are inverses of each other.
This fails however in more general rings. As happens often with such statements, one can easily force an example by dividing out suitable things from a polynomial ring. Take $R=k[a,b,u,v]/(a-vb,b-ua)$ for some field (or ring) $k$, now we have forced $aR=bR$. However neither $u$ nor $v$ are invertible, as the evaluation $a:=0,b:=0$, which induces a morphism $R\to k[u,v]$ where the images of $u,v$ are non-invertible, shows.