Fix write mode for writefile functions