Part of simple proof of nontrivial center in p-group
$|G|=p^k$ for some $k$ as it is a $p$ group, we are only talking about finite groups here, this statement may not hold for infinite groups.
Now as $C_G(x)<G$ therefore $|C(x)|$ divides $p^k \implies |C(x)|=p^i$ for some $0 \le i < k$, so, $|G:C(x)|=p^{k-i}$ and $k-i>0$ implies $p$ divides $|C(x)|$
Hint: If $x$ is not in the center, then what contradiction would you get if $|G:C(x)|=1$.
Note: the values $|G:C(x)|$ can take are $1,p,p^2,...p^n$