Make writePort more resilient to errors

More does not mean totally. For instance deleting the file could still
go wrong.