Replace open/writelines with with statement.