BF: fix writing history to file in Python 3

Need to open file in binary mode to save text, strangely.
Merge pull request #462 from matthew-brett/fix-for-py3-streams

BF: fix writing history to file in Python 3