Irreducible "family" of relative effective divisors of a smooth morphism Let $\pi:X\rightarrow Y$ be a smooth proper (assume projective if needed) morphism of schemes with $Y$ locally noetherian, and let $Z\subset X$ be an irreducible integral closed subscheme  containing no fiber of $\pi$.


*

*Is the locus $Pic_\pi(Z)=\{y\in Y:Z_y \text{ is Cartier in }X_y\}$ closed in $Y$?

*If not, what extra hypotheses would make it closed?


As $\pi$ is smooth, Cartier and Weil divisors on fibers are the same, and as it is proper, the dimension of fibers is semicontinuous, so the issue is actually about components of smaller dimension in the fibers. Thus I'd drop the hypothesis on not containing fibers and replace it by the hypotheses that $Z$ dominates $Y$; then the question would be:


*

*Is the locus of $y$ such that $Z_y$ has a (possibly embedded) component of codimension $\ge 2$ in $X_y$ open in $Y$?


I have the feeling that this is related to Zariski's main theorem, although in the first formulation it seems closer to asking whether the subscheme of relative effective divisors is closed in the Hilbert scheme when $\pi$ is smooth. But I can't pin it down.
(In my situation, $Z$ is actually of codimension 2, and everything is over the complex field, but I don't think this is necessary).
 A: In fact both sets are constructible in $Y$. 
Suppose for simplicity that $X$ is connected. Then the dimension of the (non-empty) fibers of $X\to Y$ is constant (EGA IV.12.1.1(i), and flatness is enough), denote it by $d$. Let $Y'$ be the (integral) image of $Z$ in $Y$. We can replace $X\to Y$ by $X\times_Y Y'\to Y'$ and suppose that $Z\to Y$ is surjective. Let $e$ be the dimension of the generic fiber of $Z\to Y$. 
Special case: $e=d-1$. By Chevalley's theorem (EGA IV.13.1.1), for any $y\in Y$, the irreducible components of $Z_y$ all have dimension $\ge d-1$. By hypothesis, $Z_y\ne X_y$, hence $\dim Z_y\le d-1$. 
Therefore $ \mathrm{Pic}_\pi(Z) = Y $ (and it is closed in $Y$ if $Z$ doesn't dominate $Y$). 
General case. The set of $x\in Z$ such that $\dim_x Z_{\pi(x)}\le d-2$ is open in $Z$ (EGA IV.13.1.3). The complementary of the image by $\pi$ of this open subset is constructible and is your 
${Pic}_{\pi}(Z)$. 
In case $Z\to Y$ is flat, then $\mathrm{Pic}_\pi(Z)$ is closed by openess of  $\pi|_Z$.
For the second question, if $F$ denotes the set of $x\in Z$ such that all associated components of $Z_{\pi(x)}$ passing through $x$ have dimension $\ge d-1$, then you are considering $\pi(X\setminus F)$. By EGA, IV.9.9.2(iii), $F$ is constructible, so your set is constructible. 
If $Z\to Y$ is moreover flat, then $F$ is open by EGA, IV.12.1.1(i) (I learn recently this reference from an anonymous referee.), hence your set $\pi(X\setminus F)$ is in fact closed.
A: Take $Y=\mathbb{A}^1$ (with coordinate $t$), and $X=\mathbb{P}^2_Y$ with homogeneous coordinates $u$, $v$, $w$. Now let $Z$ be the zero scheme of $(tu, u^2, uv)$. Over any point $y$ where $t\neq0$, $X_y$ is the line $u=0$ in $\mathbb{P}^2$, while $X_0$ is defined by $u^2=uv=0$, hence has an embedded component.
A: This should be a counterexample.
Let $n$ be sufficiently large, and let $Y = \mathbb{G}(2,n)$ be the Grassmannian of $\mathbb{P}^2$'s in $\mathbb{P}^n$.  Take $X = \{ (p,\Lambda):p\in\Lambda \}$ to be the universal $2$-plane over $Y$.  Let $S\subset \mathbb{P}^n$ be a surface which contains a line $L$ (perhaps a rational surface scroll, but there are lots of things to try), and let $Z = \{(p,\Lambda): p\in S \}\subset X.$  Then $Z$ is irreducible.  I'd expect that the general $2$-plane $\Lambda_0$ which contains $L$ will not intersect $S$ in any other points (say $n\geq 5$), i.e. that the corresponding fiber $Z_{\Lambda_0} \subset X_{\Lambda_0} \cong \mathbb{P}^2$ is a Cartier divisor.  But for more special choices of $2$-plane containing $L$, the intersection will be $L$ together with a finite collection of points, and so the fiber will not be a divisor.
