Path(temp_file.name).write_text(template, encoding="utf-8")
to suppress the error :
Best regards
Gilles