Best bet? With that approach you'd probably want to have 3 files on the server:
1. The first part of the page (before the messages)
2. The messages part of the page
3. The last part of the page (after the messages)
At the end of part 1, include parts 2 and 3.
When you add a message to part 2, just open it in append mode.