Proof (affine algebraic set is irreducible iff ideal is prime)
Reducible $\implies$ not a prime ideal
Suppose $X = X_1 \cup X_2$ where $X_1$ and $X_2$ are proper closed sets of $X$, i.e. affine algebraic sets properly contained in $X$. Since $I(X) = I(X_1) \cap I(X_2)$ and $I(X_i) \supsetneq I(X)$, there exists $f_1\in I(X_1) \setminus I(X_2)$ and $f_2 \in I(X_2) \setminus I(X_1)$.
Then $f_1f_2 \in I(X_1) \cap I(X_2) =I(X)$ (as $I(X_1), I(X_2)$ are ideals) but $f_1, f_2\not\in I(X)$, so $I(X)$ is not prime.
Not a prime ideal $\implies$ reducible
Suppose $I(X)$ is not a prime ideal, i.e. there is $f_1, f_2\in k[x_1, \ldots, x_n] \setminus I(X)$ with $f_1 f_2\in I(X)$. Define $$ \begin{align*} X_i := X \cap Z(f_i) \subsetneq X, \quad i=1,2, \end{align*} $$ which are affine algebraic sets, properly contained in $X$ as $f_i\not\in I(X)$. Now $$ \begin{align*} X_1 \cup X_2 = X \cap (Z(f_1) \cup Z(f_2)) = X \cap \underbrace{Z(f_1 f_2)}_{\supseteq X} = X \end{align*} $$ as required.