Prime ideal implies irreducible affine variety Let $X$ be some affine variety. I am trying to understand why if $I(X)$ is prime, then $X$ is irreducible. In a proof here, the author states:

Let $I(X)$ be a prime ideal, and suppose that $X=X_1\cup X_2$. Then $I(X)=I(X_1)\cap I(X_2)$. As $I(X)$ is prime, we may assume $I(X)=I(X_1)$, so $X=X_1$.

My question is about this last sentence: "As $I(X)$ is prime, we may assume $I(X)=I(X_1)\dots$" What about the primeness of $I(X)$ implies this?
For context, the reference the author provided for the last statement was

If $X_1\subset X_2\subset\mathbb{A}^n$, then $I(X_1)\supset I(X_2)$.


Clearly $I(X)\subset I(X_i), i=1,2$. If $I(X)\neq I(X_1)$, then let $f\in I(X_1)-I(X)$. For any $g\in I(X_2)$, $fg\in I(X_1)\cap I(X_2)=I(X)$ and since the latter is prime and $f\not\in I(X)$, we get $g\in I(X)$. Since $g\in I(X_2)$ was arbitrary, we get $I(X_2)\subset I(X)$ and thus they are equal.
