More conceptually: the set $I = \{n\in \Bbb Z\ :\ n x \in \Bbb I\}$ is easily verified to be a (denominator) ideal.
Since $I$ contains $pM,N$ it contains their gcd $\,(pM,N) = (M,N),\,$ so also its multiple $M$.
Remark $ $ Likely you are familiar with more elementary manifestations such as the well-known fact that if a fraction can be written with denominators $\,c,d\,$ then it can be written with denominator $\,\gcd(c,d),\,$ or analogous results about orders of elements, e.g. here.. Conceptually it is better to avoid direct Bezout-based proofs and instead think of these results in terms of denominator or order ideals..
I used an exact order analog here, where I mention the fractional form below (with your notation)
Lemma $ $ If a fraction is writable with denominator $\,N\,$ and also with denominator $\,pM\,$ where $(N,p)=1$ then the fraction can be written with denominator $\,M$.
The order form used there is as follows.
Lemma $\,\ $ If $\ (N,p)=1\,$ then $\, a^{\large N}\equiv 1\equiv a^{\large pM}\, $ $\Rightarrow\, a^{\large M}\equiv 1$