Always explicitely use utf-8 when reading/writing files
It uses the locale encoding by default otherwise which is probably not what we want when generating files, and also explodes with Unicode on Windows.
Explicitely pass utf-8 as an encoding for all open() calls to fix this.
Note: Missing encoding arguments can be detected on all platforms starting with Python 3.10 if the PYTHONWARNDEFAULTENCODING env var is set, see https://peps.python.org/pep-0597 for more details.