A Hartogs-type criterion for flatness

Let $U$ be a smooth affine connected variety over $\mathbb C$ and let $V\subset U$ be an open whose complement is of codimension at least two.

Now, let $Y$ be a smooth quasi-affine connected variety with trivial class group $\mathrm{Cl}(Y) =0$ and let $V\to Y$ be a smooth surjective morphism. This induces a natural morphism $U\to$ Spec $\mathcal O(Y)$.

Is the morphism $U\to$ Spec $\mathcal O(Y)$ flat? (The answer is positive if $\dim Y <2$.)

If not, what if $Y$ is assumed to be affine? What if we assume $\mathcal O(Y)$ to be a UFD?

I expect the answer to be negative, but I can't think of an easy example.

• Quotients by finite group actions give counter examples in the general case, e.g. see the answer to this question: mathoverflow.net/questions/169052/… Take $U = k^2$, $V = U\setminus$origin, $Y =$ image of $V$ by the quotient map. – auniket Apr 19 '16 at 22:44