Suppose that I have a proper morphism $f: X \to Y$ of varieties (i.e. reduced separated schemes of finite type). I am given that (a) on a dense open $U \subseteq Y$, $f$ is an isomorphism (i.e. $X\times_Y U \to U$ is an isomorphism), and (b) the pullback $(Y\backslash U)\times_Y X \to Y\backslash U$ is also an isomorphism. (Both pullbacks here are in the category of schemes.) Does it follow that $f$ must be an isomorphism?

(ETA: clarification of the condition that I need.)

It's clearly the case that this is not true if the schemes are not varieties, because the map $\operatorname{Spec}k \to \operatorname{Spec} k[\epsilon]/(\epsilon^2)$ is proper but not an isomorphism, but setting $U = \operatorname{Spec}0$ gives the above properties. But with the extra condition of varieties this seems to work, but a sanity check would be very helpful. Does anyone know of a reference for this, or a reason it's true/not true?