Why the rank of a locally free sheaf is well defined?
Actually, there are two different restriction maps:
The first one (the one you correctly say is neither surjective nor injective in general) is that on sections: for $\mathcal{F}$ a sheaf on a scheme $X$ and two open subsets $V \subseteq U$, there is a map $\mathcal{F}(U) \to \mathcal{F}(V)$.
On the other hand, the inclusion map $i_{VU}: V \to U$ induces a functor $i_{VU}^{-1}$ from the category of sheaves on $U$ to the category of sheaves on $V$. This is called restriction of sheaves. By functoriality, $W \subseteq V \subseteq U$ yields $i_{WV}^{-1}\circ i_{VU}^{-1} = i_{WU}^{-1}$, so the notation is usually shortened to just $ -|_{W}$.
The second one is the one that you want to look at: the statement is then that $\mathcal{F}|_{U} \cong \mathcal{O}_X^{\oplus I}|_{U}$ implies $\mathcal{F}|_{V} \cong \mathcal{O}_X^{\oplus I}|_{V}$ for $V \subseteq U$.
Locally free means not just that $F(U)$ is a free $O_X(U)$-module for an open cover of $U$'s, but that as a sheaf the restriction $F|_U$ is isomorphic to a direct sum of copies of $O_X|_U$. In particular, this gives an isomorphism of $F(V)$ with a corresponding sum of copies of $O_X(V)$ for every open subset $V\subseteq U$.
Let $\mathcal{F}$ be a locally free sheaf on $X$. For any $x$ in $X$ there exists $x \in U \subset_{open} X $ such that
$\mathcal{F}|_U \cong \mathcal{O}_X|_U^{(I)}$ $ \ \ \ \ (\star)$.
In particular, for each $y$ in this particular $U$, one has $\mathcal{F}_y \cong \mathcal{O}_{X,y}^{(I)}$ (which is given by the isomorphism above!!!).
Suppose now $X$ is connected and $\mathcal{F}$ is locally free (we need this). Fix an indexing set $I$ (and I think I need to take this $I$ to be one of the indexing sets from $(\star)$ above). The properties of $\mathcal{F}$ show that the set
$S_I = \left(x \in X : \mathcal{F}_x \cong \mathcal{O}_{X,x}^{(I)}\right)$
is both closed and open in $X$. We know that there exists
$x$ in $X$ with $\mathcal{F}_x \cong \mathcal{O}_{X,x}^{(I)}$,
we have $S_I = X$.
In particular, $\text{rank}_{\mathcal{O}_{X,x}}(\mathcal{F}_x)$ is constant as $x$ varies in $X$.