It is true with some extra assumptions. If $f$ is projective (EDIT: in fact proper is enough) and has connected and (EDIT) reduced fibers and $M$ is a line bundle that is trivial on every fiber, then $h^0(X_y, M)=1$ for every $y\in Y$. If $Y$ is integral, then it follows that $L:=f_*M$ is a line bundle and the natural map $f^*L\to M$ is an isomorphism.
EDIT: the argument works provided $h^0(X_y, {\mathcal O})=1$ for every $y$. So in some cases one can remove the assumption that all the fibers are reduced. For instance if $X$ is a smooth complex surface and $Y$ is a smooth curve, then by Zariski's lemma every fiber $X_y$ is either $1$-connected or $X_y=mD$, where $D$ a $1$-connected divisor and $D|_D$ is torsion of order $m$. Using the fact that $h^0({\mathcal O}_D)=1$ if $D$ is $1$-connected and applying induction, one gets $h^0(X_y, {\mathcal O})=1$ for every $y$.