This pull request fixes the UnicodeEncodeError that was occurring when writing to a file. Updated the multiple open() calls to specify UTF-8 encoding.