Add begin rescue block when writing to pipe in order to protect againts broken pipes