Solution (source code)

= Solution

For a Noetherian separated integral scheme regular in codimension one, a <Weil divisor> is a finite integer combination of integral codimension-one closed subschemes. Principal divisors are the valuation divisors of nonzero rational functions, and the <divisor class group> is
$$
\operatorname{Cl}(X)=\operatorname{Div}(X)/\operatorname{Prin}(X).
$$

For an open immersion $U\subseteq X$, restriction induces a surjection
$$
\operatorname{Cl}(X)\twoheadrightarrow\operatorname{Cl}(U):
$$
every prime divisor of $U$ closes to a prime divisor of $X$, while divisors supported in $X\setminus U$ form the kernel. Therefore $\operatorname{Cl}(X)=0$ implies $\operatorname{Cl}(U)=0$.

Affine schemes need not have trivial class group. For example,
$$
X=\operatorname{Spec}k[x,y,z]/(xy-z^2)
$$
is a normal affine surface with $\operatorname{Cl}(X)\cong\mathbb Z/2\mathbb Z$. The height-one prime $(x,z)$ represents the nonzero class: twice this divisor is the principal divisor of $x$, but the divisor itself is not principal.