A workaround for Windows where it blocks deletion of file is to truncate the file:
outputFile = open(r"filename.txt","w")
outputFile.truncate()
outputFile.close()
outputFile = open(r"filename.txt","a+")
source: https://stackoverflow.com/a/2769090/6345724