$\mathbb{A}^2\setminus (0,0)$ is often given as an example of a variety that is not affine. I am trying to understand this example better by seeing it as a special case of a natural general claim.
Claim: Let $X$ be an affine variety over an algebraically closed field $k$ such that $k[X]$ is a UFD. Let $Y$ be any closed subset of codimension at least 2. Then $X\setminus Y$ is not affine.
Is this the right general claim?
If so, can I drop the assumption that $k$ is algebraically closed, or is that needed?