Ensure unicode
Add some safety to file writing