TITLE: Is locally freeness of a sheaf (of fixed rank) around a divisor detectable from a first order neighbourhood?
QUESTION [5 upvotes]: Assume you have a smooth projective variety $X$ over the complex numbers, a smooth prime divisor $D$ on it, and a torsion free coherent sheaf $E$ on $X$ of rank $r>0$. Let $E|_{2D}:=E\otimes_{\mathcal{O}_X}\mathcal{O}_{2D}$, where $\mathcal{O}_{2D}:=\mathcal{O}_{X}/\mathcal{I}_{D}^2$, be the restriction of $E$ to the first order neighbourhood of $D$ in $X$.
If $E|_{2D}$ is a locally free $\mathcal{O}_{2D}$-module of rank equal to $r$, can we conclude that $E$ is locally free in a (Zariski) neighbourhood of $D$ (necessarily of rank $r$)?
Does it change anything if we assume $X$ is a surface and/or that $E$ is semistable?

REPLY [6 votes]: Let $X$ be a connected reduced noetherian scheme and $\mathscr F$ a coherent sheaf on $X$. Let $\varrho(x)=\dim_{\kappa(x)}\mathscr F_x\otimes \kappa(x)$ where $x\in X$ is a point and $\kappa(x)$ is the residue field at $x$. 
Using Nakayama's lemma you can prove the following:
The function $\varrho$ is upper semi-continuous on $X$ in the sense that the set
$$
Z_m:=\{x\in X \ \vert \ \varrho(x)\geq m \} 
$$
is closed for any $m\in \mathbb Z$. 
It follows that if $\mathscr E$ is a torsion-free sheaf of rank $r$, then $Z_m=\emptyset$ for $m<r$ and $Z_r=X$. 
Furthermore, $\mathscr E\left|_U\right.$ is locally free where 
$$
U:=\{x\in X \ \vert \ \varrho(x)=r \}. 
$$
It looks like that in your case $D\subseteq U$ and hence $U$ gives you the open set you are looking for. In fact, it seems that a lot less is enough for this than what you have. 
I don't think $X$ being a surface or $\mathscr E$ being semistable makes any difference. After all how could this be any better? :)