Fix bug that the type text to write is not suitable with file object in Python 3.