Good suggestions. How fast is your data changing? Are you discarding data that you may need? It looks like you are pushing a lot of data into the file, you may want run the acquire data function and the save data functions in separate loops and use notifiers or, use object-oriented programming to get rid of some of the dependancy.
>
"There is a God shaped vacuum in the heart of every man which cannot be filled by any created thing, but only by God, the Creator, made known through Jesus." - Blaise Pascal