Python: File overwrite and append in python