It is instructive to view this from a slightly more general perspective. The equivalence of the two common forms of the Little Fermat theorem is special case $\, f(x) = x^{p-1}-1\,$ below.
Theorem $\ $ If $\,p\,$ is prime and $f(x)$ is polynomial with integer coefficients then
$$\begin{align}
&p\mid x f(x)\ \text{ for all integers } x\\[.2em]
\iff\ &p\mid f(x) \ \ \ \:\! \text{ for all integers } x\ \text{coprime to } p
\end{align}$$
Proof $\ (\Rightarrow)\ $ By hypothesis $\,p\mid xf(x),\,$ so $\,x\,$ coprime to $\,p\Rightarrow\,p\mid f(x)\,$ by Euclid's Lemma.
$(\Leftarrow)\ $ We split into two cases depending on whether or not $\,p\mid x$.
Case $(1)\ \ p\mid x.\ $ Then $\,p\mid xf(x).$
Case $(2)\ \ p\nmid x,\,$ so $\,x\,$ is coprime to $\,p,\,$ so by hypothesis $\,p\mid f(x)\,$ so $\,p\mid xf(x).\ $ QED
Remark $\, $ If you know modular arithmetic then it can be viewed more arithmetically as the following in the $\color{#0a0}{\rm domain}$ $R=\Bbb Z_p$ (true for a polynomials over any field or domain)
$$\begin{align} \forall x\!:&\ \ \ \ \ \ \ xf(x)= 0\\[.2em]
\iff\ \forall x\ &\ [\:\!x\not= 0\Rightarrow f(x)= 0\:\!]\\[.6em]
{\rm generally}\quad \forall x\!:&\ \ \ \ \ \ g(x)\:\!f(x)= 0\\[.2em]
\iff \ \forall x\ &\ [\:\!g(x)= 0\ \ {\rm or}\ \ f(x)= 0\:\!]\ \ \text{by $\,R\,\ {\rm a}\ \color{#0a0}{\rm domain}$}\\[.2em]
\iff\ \forall x\ &\ [\:\!g(x)\not= 0\,\Rightarrow\:\! f(x)= 0\:\!]\end{align}$$