In the local setting after having localized everything at $\mathfrak{m}$, suppose that $p$ generates $\mathfrak{m}$. A module over $A$ is flat iff it is $p$-torsion free. So suppose that $px=fy$ for $x,y \in B$. Then $fy \in \mathfrak{m}B$, this implies that $y \in \mathfrak{m}B$, because $f$ is not a zero divisor in $B/\mathfrak{m}B$. Thus $y \in \mathfrak{m}B=pB$, write $y=pz$ for $z \in B$.
Using the equation $px=fy$, we get $px=fpz$, but because $B$ is flat, i.e. torsion-free, we can cancel $p$ and get $x=fz$