You're using "w+" which will truncate the file (This mode opens the file for both reading and writing, but it truncates (clears) the file as soon as it's opened).
Instead, you should open it in write mode ("w") after you've collected the new content to avoid overwriting.