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.