$\newcommand{\scrO}{\mathscr{O}}$ $ \newcommand{\A}{\mathbb{A}}$
Problem: A proper subset $X \subset \A^1_k$ is closed if and only if it is finite.
Here the topology being considered is the Zariski topology so the closed sets are exactly the algebraic sets. Here is a proof of the reverse direction from a book.
We know that if $I$ is a maximal ideal of $\scrO(\A^n)$ that $V(I) = \{p\}$ and so singletons are algebraic sets corresponding to maximal ideals of $\scrO(\A^n)$. Therefore because singletons are closed and as a topology finite unions of closed sets are closed it follows that any finite set is closed.
What I don't understand is why this approach. What I had thought was the following, which seems more intuitive but where is it wrong?
Let $X = \{x_1,\dots,x_m\}$. Then let $f = \prod_1^m (x-x_i) \in \scrO(\A^1) = k[x]$. Notice that $V(f) = X$ where $V$ denotes the vanishing set of the polynomial. Therefore $X$ is algebraic as it corresponds to the vanishing set of some $f \in k^1$.
Your approach also works.
In fact if you replace the polynomials $(x - x_i)$ by an ideal defining the point $x_i$ it also generalizes to both of the situations noted in the comments. In general $V(I) \cup V(J) = V(IJ)$. If $X = \mathbb{A}^1$ then $k[X]$ is a PID so all the ideals are principal and if further $k$ is algebraically closed then the only maximal ideals (points) are generated by polynomials of the form $x - x_i$ so in this case it reduces to exactly what you wrote.
Depending on definitions some version of this should be involved in checking that the Zariski topology is a topology, so is also implicit in what the book says.