Open affine subscheme of affine scheme which is not principal
Let X be an elliptic curve with the identity element O removed. Let U=X-P where P is a point of infinite order. Then U is affine by a Riemann-Roch argument. Now suppose that U=D(f). Then on the entire elliptic curve, the divisor of f must be supported at P and O only. This implies that P is a torsion point, a contradiction.
For a simple, really concrete example you can also look at:
$A=k[x,y,u,v]/(xy+ux^2+vy^2)$, $X =Spec(A)$, $I=(x,y)$, $U = D(I)$.
Then the functions $f=\frac{-v}{x}=\frac{y+ux}{y^2}$ and $g=\frac{-u}{y}=\frac{x+vy}{x^2}$ are defined on $U$. But $yf+xg=1$, so $U$ is affine!
Cheers,
I just want to remark that there is a purely categorical characterization of the ideals $I \subseteq A$ such that the corresponding open subscheme $D(I) = V(I)^c$ of $\text{Spec}(A)$ is affine, namely that the ideal $I$ is codisjunctable. This means that there is a universal homomorphism $A \to B$ satisfying $IB=B$. This notion is studied in
Yves Diers, Codisjunctors and Singular Epimorphisms in the Category of Commutative Rings, Journal of Pure and Applied Algebra, 53, 1988, pp. 39 - 57