Fix issue with writelines in python3