use 'with as' to read and write file instead