Change save function

- Throw exceptions in the save function if folder is not writable or if
there is an error during file saving.
- Prevent error when the folder name contains a trailing slash