Let $f:X \to Y$ be a morphism of varieties and let $Z \subset X$ be a closed subset. Assume that $f^{-1}(p) \cap Z$ is irreducible and of the same dimension for all $p \in Y.$ Show that $Z$ is irreducible.
Here is what I tried:
Assume the contrary and let $Z=Z_1 \cup Z_2$ where $Z_i$s are closed in $Z.$ By assumption, $f^{-1}(p) \cap Z=(f^{-1}(p) \cap Z_1) \cup (f^{-1}(p) \cap Z_2)$ is irreducible, so let $U=\{p \in Y|\; f^{-1}(p) \cap Z=f^{-1}(p) \cap Z_1 \}$ and $V=\{p \in Y|\; f^{-1}(p) \cap Z=f^{-1}(p) \cap Z_2 \}.$ My strategy is to prove that $U,V$ are closed in $Y$ and get the contradiction ( $Y$ is a variety, so irreducible). For instance, consider $U \subset Y.$ Then $Y$ has a finite open affine cover by $Y_i$s, so is enough to show that $U \cap Y_i$ is closed in $Y_i$ for all $i.$ I also know that there is an open subset in $W \subset Y$ s.t. all fibers $f^{-1}(x)$ have the same dimension for all $x \in W,$ but I got stuck and don’t know how to proceed and use the fact that $f^{-1}(p) \cap Z$ have the same dimension for all $p \in Y.$