It should be noted that in fact $i\neq j \implies x_i+IM\neq x_j+IM$ is a special case of the linear independence of $\{x_i+IM\}_{i\in I}$. For convenience here is the same argument with a different packaging. The proof will be based on the special case of vector spaces:
Theorem: If $V$ is a $k$-vector space and $\mathcal{X},\mathcal{Y}$ are two $k$-bases of $V$, then $\operatorname{card}(\mathcal{X})=\operatorname{card}(\mathcal{Y})$.
For preliminaries we have the following:
Let $\operatorname{sca}:R\times M\to M$ define the $R$-module structure of $M$, and $I\in\mathcal{P}_{\unlhd}(R)$. Then
- $IM:=\bigcup_{n\geq1}\left\{\sum_{k=1}^n \operatorname{sca}(a_k,m_k)\vert a_k\in I,m_k\in M\right\}$ is a submodule of $M$ with $ \operatorname{sca}\vert_{R\times IM}$.
- That being the case the quotient group $M/IM$ too has an $R$-module structure, given by\begin{align}
\widetilde{\operatorname{sca}}:&R\times M/IM\to M/IM\\
&(a,m+IM)\mapsto \operatorname{sca}(a,m)+IM
\end{align}
- Finally (since $I\subseteq (M/IM)^\circ$) we have an $R/I$-module structure on $M/IM$ given by\begin{align}
\overline{\operatorname{sca}}:&R/I\times M/IM\to M/IM\\
&(a+I,m+IM)\mapsto \widetilde{\operatorname{sca}}(a,m)=\operatorname{sca}(a,m)+IM.
\end{align}
- In the case when $I$ is maximal $R/I$ is a field, hence $M/IM$ becomes an $R/I$-vector space with $\overline{\operatorname{sca}}$ as the scalar multiplication.
To make it less painful to read the actual proof I will not be using $\operatorname{sca}$ and its kin from now on, as is customary.
Claim: Let $R$ be a nonzero commutative ring and $M$ an $R$-module. Then any two $R$-bases of $M$ have the same cardinality.
Proof of Claim: Let $\mathcal{X}:=\{x_j\}_{j\in J}$ be an $R$-basis of $M$, $I\in\mathcal{P}_{\unlhd}(R)\setminus\{R\}$ be maximal. Set $\overline{\mathcal{X}}:=\mathcal{X}+IM=\{x_j+IM\}_{j\in J}$. Then $\overline{\mathcal{X}}$ is an $R/I$-basis of $M/IM$:
- To see that $\overline{\mathcal{X}}$ spans $M/IM$, let $m+IM\in M/IM,$ i.e. $m\in M$.
\begin{align}
&\implies \exists \mbox{ finite } J_0\subseteq J, \{a_j\}_{j\in J_0}\subseteq R: m=\sum_{j\in J_0}a_jx_j\\
&\implies m+IM=\left(\sum_{j\in J_0}a_jx_j\right)+IM=\sum_{j\in J_0}(a_j+I)(x_j+IM), \checkmark.
\end{align}
- Next we show that $\overline{\mathcal{X}}$ is $R/I$-linearly independent. Let $J_0\subseteq J$ be finite and $\{a_j\}_{j\in J_0}\subseteq R: \sum_{j\in J_0}(a_j+I)(x_j+IM)=IM$.
\begin{align}
\implies \sum_{j\in J_0}a_jx_j\in IM \implies \exists \{b_k\}_{k=1}^n\subseteq I,\exists \{m_k\}_{k=1}^n\subseteq M:\sum_{j\in J_0}a_jx_j=\sum_{k=1}^n b_km_k.
\end{align}
Since $\mathcal{X}$ is an $R$-basis of $M$, $\forall k,\exists$ finite $J_k\subseteq J, \exists\{c_j^k\}_{j\in J_k}\subseteq R: m_k=\sum_{j\in J_k}c_j^kx_k$. Setting $J':=\bigcup_{k}J_k$, we have $\forall k:m_k=\sum_{j\in J'}c_j^k\chi_{J_k}(j)x_j$.
\begin{align}
&\implies \sum_{j\in J_0}a_jx_j=\sum_{k=1}^n b_km_k=\sum_{k=1}^nb_k\left(\sum_{j\in J'}c_j^k\chi_{J_k}(j)x_j\right)
= \sum_{j\in J'} \underbrace{\left(\sum_{k=1}^n b_kc_j^k\chi_{J_k}(j)\right)}_{=:d_j\in I} x_j \\
&\implies 0 = \sum_{j\in J_0\setminus J'}a_jx_j + \sum_{j\in J_0\cap J'}(a_j-d_j)x_j +\sum_{j\in J'\setminus J_0}(-d_j)x_j\\
&\implies \forall j\in J_0\setminus J': a_j=0\in I;\;\forall j\in J_0\cap J': a_j=d_j\in I;\;\forall j\in J'\setminus J_0:d_j=0\\
&\implies \forall j\in J_0: a_j\in I \implies \forall j\in J_0: a_j+I=I,\checkmark.
\end{align}
Next observe that $\operatorname{card}(\mathcal{X})=\operatorname{card}(\overline{\mathcal{X}})$:
- $\operatorname{card}(\mathcal{X})\geq\operatorname{card}(\overline{\mathcal{X}})$ by construction.
- If $x_i+IM=x_j+IM$ but $i\neq j$, then $x_i-x_j\in IM$, which implies by the above argument for $R/I$-linear independence that $1\in I$, but $I$ is maximal, $\unicode{x21af}$. Thus $\operatorname{card}(\mathcal{X})\leq\operatorname{card}(\overline{\mathcal{X}})$ as well.
Finally let $\mathcal{Y}$ be an arbitrary $R$-basis of $M$. Then we have
$$\operatorname{card}(\mathcal{Y})=\operatorname{card}(\overline{\mathcal{Y}})=\operatorname{card}(\overline{\mathcal{X}})=\operatorname{card}(\mathcal{X}),$$
where the second equality follows from the theorem that addresses the vector space case, which applies by 4 above.
Note: For future reference this is also Exercise III.2 from Lang's Algebra, 3e (p. 165) (where the context is to generalize the result from vector spaces to free modules over nonzero commutative rings, hence my argument).
Note 2: After all this maybe it's a good idea also to observe that the converse is not true, even in the case of vector spaces, e.g. considering $\Bbb{R}[X]$ as an $\Bbb{R}$-vector space, we have $\operatorname{card}(\{X^n\vert n\geq0\})=\operatorname{card}(\{X^n\vert n\geq1\})$.