Suppose $R$ is a local Noetherian domain, and $M$ is a finitely generated $R$-module. Furthermore, let's suppose there exists $k>0$ such that $ \dim_{R_\mathfrak{p}/\mathfrak{p}R_\mathfrak{p}}M_\mathfrak{p}/\mathfrak{p}M_\mathfrak{p}=k $ for any prime $\mathfrak{p}\in\operatorname{spec}(R)$.
I've been curious though, how does this imply that $M$ is in fact a free module? I figure you want to extract some basis for $M$ from a generating set $\{x_1,\dots,x_n\}$, and this is where the dimension condition comes in. However, after localizing at $\mathfrak p$ and taking quotients, I'm losing sight of how to connect to the two ideas.
Can someone explain why $M$ is free here? Thank you.