write to a file, manage back pressure and buffering