Use the codecs module for opening and writing files