Hi Gerald,
What you need to do is write to a file continuously, i.e. after each point you collect. You can do so by opening a new/existing file, write to it inside your while loop, and close it once you are done collecting and writing data points, i.e. outside the loop.
I believe the following example is a good demonstration of that operation.
Best of luck,
AG