To answer your concrete question directly, we look at the closed subscheme $V=(X=Z=0)$ in $\operatorname{Spec}k[X,Y,Z,W]/(XY-ZW)-\{(0,1,0,0)\}$, then $V$ is isomorphic to $\operatorname{Spec}k[Y,W]-\{(1,0)\}$ which is isomorphic to $\mathbb{A}_k^2-0$, so $V$ is not an affine scheme. But any closed subscheme of an affine scheme is affine, so $\operatorname{Spec}k[X,Y,Z,W]/(XY-ZW)-\{(0,1,0,0)\}$ is not affine.
For your guess, I think it is correct when the affine variety is normal.
Proposition: For any noetherian, integral, normal affine scheme $X=\operatorname{Spec}A$, and any nonempty closed subscheme $Z$ of $X$ with codimension at least $2$, $X-Z$ is not an affine scheme.
Proof: If $X-Z$ is affine, then $i:X-Z\rightarrow X$ is a morphism of affine schemes, hence $i$ is totally determined by $i^\#:\Gamma(X, \mathcal{O}_{X})\rightarrow \Gamma(X-Z, \mathcal{O}_{X-Z})=\Gamma(X-Z, \mathcal{O}_{X})$. Since $X$ is integral, $i^\#$ is injective.
Moreover, since $Z$ does not contain any codimension $1$ point of $X$, so for any $f\in \Gamma(X-Z, \mathcal{O}_{X})$, $f$ is regular at all codimension $1$ points. Hence by the algebraic Hartog theorem, $f$ is regular on $X$ because $A$ is integrally closed. As a result, $i^\#$ is surjective.
In sum, $i^\#$ is both injective and surjective, so it is actually an isomorphism. Therefore $i$ is an isomorphism, which means $Z$ is empty and we get a contradiction! QED
(Will this proposition fail when $X$ is not normal?)