The first thing to note is that you are calling
File.WriteAllText
inside a loop - and that method will always overwrite any existing file content - so after the loop you will always get only the final message that you process.
Second is to see that you are calling Tostring on a string - which does nothing.
Finally, you need to use the debugger to find out what is going on here: we can't do that for you! Start by putting a breakpoint on the line:
int messageCount = client.GetMessageCount();
And run your code. when it stops, single step the line, and look at the count - is it zero? If it is, that's the reason. If not, continue single stepping and look at exactly what is being returned at each stage. It should be fairly obvious where the problem is if you do that, and that should tell you where to start looking to fix it.