$pi_0: Spto Ab$ is a direct sum preserving functor, and it sends $E_1$-ring spectra to rings, and modules over them to modules over them.

In particular you get a functor $pi_0: Mod_Rto Mod_{pi_0(R)}$. If $R^nsimeq R^m$ as $R$-modules, then $pi_0(R)^ncong pi_0(R)^m$ as $pi_0(R)$-modules. So if $pi_0(R)$ is commutative and nonzero (which is a much weaker hypothesis than $R$ having an $E_infty$-structure), this implies $n=m$.

More generally, it suffices that $pi_0(R)$ have the invariant basis property.

Note that conversely, if $pi_0(R)$ does *not* have the invariant basis property, we can find inverse nonsquare matrices $M,N$ with coefficients in $pi_0(R)$, and you can view them as elements of $pi_0map_R(R^n,R^m)$ ($pi_0map_R(R^m,R^n)$ respectively), and their matrix product corresponds to the composition up to homotopy, so that $R^nsimeq R^m$ as $R$-modules.

So it’s an “if and only if” situation with $pi_0(R)$.

A related claim is the fact that group-completion $K$-theory only sees $pi_0$, namely if $R$ is a ring spectrum, then the group-completion $K$-theory of projective $R$-modules (summands of $R^n$ for some finite $n$, no shifts) is the same as that of $tau_{geq 0}R$, which is the same as that of $pi_0(R)$.