Are you re-initializing the array in your vi every time it executes?
If not, the array will keep on growing. When you open the file for
writing, what mode are you using, append or replace? If append, the
file will continue growing, if replace the file will only hold the
latest data. You have to match what you are doing with the array with
how you open the file. It might be best to open the file for append
and write the latest data only, initializing your array at each loop
so that it holds only the latest data.