Modified file write parameters to handle python 3

I am using python3 and was getting the error as
"f.write(html.encode('utf-8'))
TypeError: must be str, not bytes"

In searching for the error, it was found that in python3 that it should be opened in binary mode.
More discussion about it is at : http://stackoverflow.com/questions/5512811/builtins-typeerror-must-be-str-not-bytes