Added file remove functionality

File is now removed if the function throws as the file wasn't written
properly

Refs #1671