You can use the append
mode instead of the write
mode as follows:
f = open('results.txt', 'a')
f.write(args + " " + str(len(i)) + "\n")
f.close()
The append
mode adds on to the existing file whereas the write
mode simply clears the file or overwrites it.