added optional file flags parameter to method write (e.g. to support appending to a file)