If the map from $X$ to the maxspec of $\mathcal O(X)$ is a bijection, then $X$ is indeed affine.
Here is an argument:
By assumption $X \to $ maxspec $\mathcal O(X)$ is bijective, thus quasi-finite,
and so by (Grothendieck's form of) Zariski's main theorem, this map factors as an open embedding of $X$ into a variety that is finite over maxspec $\mathcal O(X)$.
Any variety finite over an affine variety is again affine, and hence $X$ is an open subset of an affine variety, i.e. quasi-affine. So we are reduced to considering the case when $X$ is quasi-affine, which is well-known and straightforward.
(I'm not sure that the full strength of ZMT is needed, but it is a natural tool
to exploit to get mileage out of the assumption of a morphism having finite fibres, which is what your bijectivity hypothesis gives.)
In fact, the argument shows something stronger: suppose that we just assume
that the morphism $X \to $ maxspec $\mathcal O(X)$ has finite non-empty fibres,
i.e. is quasi-finite and surjective.
Then the same argument with ZMT shows that $X$ is quasi-affine. But it is standard that the map $X \to $ maxspec $\mathcal O(X)$ is an open immersion when $X$ is quasi-affine,
and since by assumption it is surjecive, it is an isomorphism.
Note that if we omit one of the hypotheses of surjectivity or quasi-finiteness, we can find a non-affine $X$ satisfying the other hypothesis.
E.g. if $X = \mathbb A^2 \setminus \{0\}$ (the basic example of a quasi-affine,
but non-affine, variety), then maxspec $\mathcal O(X) = \mathbb A^2$, and the open immersion $X \to \mathbb A^2$ is evidently not surjective.
E.g. if $X = \mathbb A^2$ blown up at $0$, then maxspec $\mathcal O(X) =
\mathbb A^2$, and $X \to \mathbb A^2$ is surjective, but has an infinite fibre
over $0$.
Caveat/correction: I should add the following caveat, namely that it is not always true, for a variety $X$ over a field $k$, that $\mathcal O(X)$ is finitely generated over $k$, in which case maxspec may not be such a good construction to apply, and the above argument may not go through. So in order to conclude that $X$ is affine, one should first insist that $\mathcal O(X)$ is finitely generated over $k$, and then that futhermore the natural map $X \to $ maxspec $\mathcal O(X)$ is quasi-finite and surjective.
(Of course, one could work more generally with arbitrary schemes and Spec rather than
maxspec, but I haven't thought about this general setting: in particular, ZMT requires some finiteness hypotheses, and I haven't thought about what conditions might guarantee that the map $X \to $ Spec $\mathcal O(X)$ satisfies them.)
Incidentally, for an example of a quasi-projective variety with non-finitely generated ring of regular functions, see this note of Ravi Vakil's
Best Answer
This is basically a restatement of the Nullstellensatz (or a slightly weakened version of it; the full strength of the Nullstellensatz says not just that closed points are dense but that $k$-points are dense). We may assume actually $V\subseteq\mathbb{A}^n_k$ (just consider the intersection of $V$ with each $\mathbb{A}^n_k$ covering $\mathbb{P}^n_k$). We may also assume $V$ is closed in $\mathbb{A}^n_k$ (since $V$ is open in its closure, so if closed points are dense in its closure they are also dense in $V$). Say $V$ is defined by the ideal $I\subseteq k[x_1,\dots,x_n]$. Our goal is then to show any nonempty open subset of $V$ contains a closed point.
A nonempty open subset of $V$ is a union of sets of the form $D(f)\cap V$ for $f\in k[x_1,\dots,x_n]$, where $D(f)\cap V$ is the set of prime ideals in $k[x_1,\dots,x_n]$ which contain $I$ but do not contain $f$. Such prime ideals are in bijection with prime ideals in the ring $(k[x_1,\dots,x_n]/I)[f^{-1}]\cong k[x_1,\dots,x_n,y]/(I+(1-yf))$. So if $D(f)\cap V$ is nonempty, the ring $k[x_1,\dots,x_n,y]/(I+(1-yf))$ is nonzero and $I+(1-yf)$ is a proper ideal of $k[x_1,\dots,x_n,y]$. By the Nullstellensatz, this means there exists $(a_1,\dots,a_n,b)\in k^{n+1}$ on which every element of $I+(1-yf)$ vanishes. This just means that every element of $I$ vanishes on $(a_1,\dots,a_n)$ and $bf(a_1,\dots,a_n)=1$, so in particular $f(a_1,\dots,a_n)$ is nonzero. This means the maximal ideal in $k[x_1,\dots,x_n]$ corresponding to $(a_1,\dots,a_n)\in k^n$ is a closed point of $\mathbb{A}^n_k$ which is in $V\cap D(f)$. This shows any nonempty open subset of $V$ contains a closed point, so closed points are dense in $V$.