Oh, now I understand, that makes a lot of sense. I was opening and closing the file every single time in the loop, hence overwriting the data in the file on every loop iteration. I tried putting the whole open,write,close statements outside of the loop which didn't quite work either.. but...