Same comment as before, use the "with" notation, without mode=. Because you forgot to close the file :)