And replace a few instances of open().write(...) which never triggered file closing with Path.write_text(...) so they don't rely on CPython-specific behavior
This complements @marmoute's work in !354 (merged)