What you’ve done is almost right. You need to consider all subsets of $X$, not just those of the form $\{a_1,\dots,a_k\}$. For instance, if $n=5$ you have not considered the set $\{a_2,a_4\}$.
You can fix the problem in several ways. You could, for instance, let $U$ be any subset of $X$ and observe that
$$X\setminus U=\bigcup_{x\in X\setminus U}\{x\}$$
is a union of finitely many closed sets and is therefore closed, so that $U$ must be open; this is the argument that you’re using now, but done right, so that it applies to all subsets of $X$.
Alternatively, you could leave the complementation to the end. Let $A$ be any subset of $X$. Then
$$A=\bigcup_{x\in A}\{x\}$$
is the union of finitely many closed sets, so $A$ is closed. Thus, every subset of $X$ is closed. Now let $U$ be any subset of $X$; then $X\setminus U$ is closed, so $U$ is open.