Hartshorne, "Algebraic Geometry," Exercise II.7.1, reads:
Let $(X, \mathcal{O}_X)$ be a locally ringed space, and let $f : \mathscr{L} \to \mathscr{M}$ be a surjective map of invertible sheaves on $X$. Show that $f$ is an isomorphism.
To prove this, I note that a morphism of sheaves is injective (resp. surjective) iff it is injective (resp. surjective) on stalks. Thus $f_P$ is surjective for each $P \in X$. Since $\mathscr{L}$ and $\mathscr{M}$ are invertible, $\mathscr{L}_P \cong \mathscr{M}_P \cong \mathcal{O}_{X, P}$ as $\mathcal{O}_{X, P}$-modules. From commutative algebra, a surjective endomorphism of finitely-generated modules over any ring is in fact an automorphism, so $f$ is an isomorphism on stalks and thus an isomorphism of sheaves.
This argument sounds fine to me, but now I'm worried because I didn't use many of the conditions in the problem -- I could weaken it to an arbitrary (rather than locally-) ringed space, to any locally free sheaves of the same rank or even to something a bit weaker (namely that $\mathscr{L}$ and $\mathscr{M}$ are locally isomorphic), etc.
Have I missed something here? Or does the result hold in much wider generality without any modification?