add flags option to writefile