added secure random require
wrap the file saving in a rescue block