modified code to save corpus to different location if folder not writeable and added time