And the output.txt is empty.
Try this instead ...
my_file = open("output.txt", "w+")
"w+" mode, the
open function will create the file if it does not yet exist.
Thank you @appylpye, it works!
So the default "r+" doesn't work because the file hasn't been created yet, I see.