Let $R$ be an integral domain and $a,b\in R$. Suppose that $a | b$ and $b | a$. By definition, this means that $ax = b$ and $by = a$ for some $x,y\in R$, and so $b(1 – yx) = 0$. If $b\not = 0$ then $yx = 1$ and so $x$ and $y$ are units. Of course, if $b$ is zero, then $a = 0$, and in either case $b = ax$ where $x$ is a unit.
Concluding, we see that in an integral domain, if $a | b$ and $b | a$ then $b = ax$ where $x$ is a unit of $R$. Did you know that this implication can fail when $R$ is not an integral domain?
Here's a counterexample that I learned in a paper of Anderson and Valdez-Leon. Let $R = k[X,Y,Z]/(X – XYZ)$ where $k$ is a field, and let $x,y,z$ denote respectively the images of $X,Y,Z$ in $R$. Then $x | xy$ and $xy | x$, the latter because $xyz = x$. However, it is not possible to write $xy$ as a unit multiple of $x$.
Why is this? Well, first of all, $y$ is definitely not a unit in $R$ because in the quotient ring obtained by setting $x=z=0$, this would mean that $y$ would be a unit in the polynomial ring $k[y]$. On the other hand, this argument does not preclude the existence of an $f\in R$ such that $fx = xy$.
So suppose such an $f$ did exist. Then in $k[X,Y,Z]$, we would have the relation $fX – YX = gX(1 – YZ)$ for some $g\in k[X,Y,Z]$. Since $k[X,Y,Z]$, is an integral domain, we have $f = Y + g(1 – YZ)$. If $f$ were a unit in $R$, then by setting $X = 0$ we see that $Y + g(1 – YZ)$ would be a unit in $k[Y,Z]$. Setting $Y = Z$ shows that $Z + g(1 – Z^2) = Z + g – gZ^2$ would be a unit in $k[Z]$, which is impossible since the term $gZ^2$ shows $Z + g – gZ^2$ is not a constant polynomial.
I like this example not only because it's neat, but because it illustrates the principle that a good place to look for counterexamples in commutative ring theory is in the land of quotients of polynomial rings.