implement write to file