Only open browser/delete file if write succeeded

Fixes #2.