I guess one approach is that if each piece of data is on one line, you could use an array. Read the data from the file into an array, using the line breaks to separate the elements of the array, so you get something like this:
theData = '12345';
theData = '23456';
Then just assign the next value to a new element in the array (I think this is possible...), then delete the first element of the array.
Then iterate over the array, and write back to the file.
That's just off the top of my head. There are probably better solutions.