The easiest way is to open (create) the file once at the beginning of the acquisition, and leave it open. You should use DENY WRITE permissions, at least, to prevent other apps from writing the file.
Start with an empty array of data in a shift reg.
Repeat
Get new value
Use BUILD ARRAY to prepend the new value to the existing array (IN FRONT OF the old data).
Use ARRAY SUBSET to limit the array to 9000 samples.
Use SUM ARRAY ELEMENTS to figure the sum.
Use ARRAY LENGTH to find out how many you have.
Divide the sum by the number N, and that's your current average.
Write this directly to the file, or convert it to ASCII and write that.
until done.
Close file.
This maintains the ave
rage, even when you have less than 9000 samples in your buffer.
The DISADVANTAGE of this, is that the file is open during the whole event. You'll have to take special care if you want some other program to open the file while data is coming in.
That also means that the contents of the file ON DISK are not necessarily up to date - there could be a block of data in memory that's not been written to disk yet. (Because of the OS, not because of your code).