Why does the structure theorem for finitely generated modules over PIDs fail for arbitrary modules over a PID?
Consider the case of $R=\mathbb{Z}$ and $M=\mathbb{Z}_{p^{\infty}}$, the Prüfer group (the subgroup of $\mathbb{Q}/\mathbb{Z}$ generated by $\frac{1}{p^n}$ for all $n$.
Take $F$ be freely generated on countably many generators $x_n$, with $x_n$ mapping to $\frac{1}{p^n}$. Then $K$ is freely generated by $px_1$, $x_1-px_2$, $x_2-px_3,\ldots$.
The problem is that as you try to perform the procedure in step $4$, at every step you get $a_i = 1$. To see this, simply notice $M$ is divisible, so you can never have a finite direct summand. The subgroup generated by the $y_i$ does not generate $K$, but only a proper submodule of $K$. The process does not capture all of $K$.
Now, the real question is what is "morally" going wrong? I'm not sure I can give a good answer to that right now, other than to point out that it does go wrong. My feeling is that the process described is trying to arrange things so that we can describe $K$ as a "nice" submodule by a good change of basis; we arrange things so that the first coordinate is chosen nicely, and then "push" the rest of the problem to the remaining coordinates. Because at each step we can retain the things we already fixed, and we can only take so many steps before we run out of room, we eventually have fixed the problem. But in the infinitely generated case, not only do we not "run out of room", we may be unable to even fix that first coordinate in the first place! I think it comes down to the fact that even though $\mathbb{Z}$ is a PID, you can still have an infinite descending chain of ideals, like $(p)\supset (p^2)\supset (p^3)\supset\cdots$, which in a sense is what we have with $M$ above. Trying to go "transfinite" doesn't solve the problem because $\cap (p^n) = (0)$ loses all the information about the torsion of $M$. In the finitely generated case this cannot occur, because we have a definite "floor" below which we cannot go; the infinitely generated case does not have that reassurance, which is what is going wrong here and why you keep getting $a_i = 1$, so you are never actually finding a way to describe $K$ effectively this way.