Thing is every time it records it just overwrites the first line of the text file.
This is happening because when you open the file you gave mode "w". On write mode, when you start writing something in the file you start from the beginning, as a result the new text replaces the old one. You need to set append mode "a"
Here is an example:
f = open('myfile','a+')
f.write("a line\n")
f.write("a new line\n")
f.close()
We open the file in append mode, write the first line and add a new line character , then write second line , finally we close the file