Yes your change is good. That way the last layer won't have a mask applied. I wasn't sure if you wanted that, but put in the check for the background layer.
As far as saving, what file format do you want to save to? Here's how I save a psd:
var docRef = activeDocument
var doneFolder = new Folder('/c/photos/')
var layerName = docRef.activeLayer.name
var psdOptions = new PhotoshopSaveOptions();
psdOptions.layers = true;
app.displayDialogs = DialogModes.ALL;//include this line if you want the dialog box to come up.
docRef.saveAs (new File(doneFolder +'/' + layerName + '.psd'), psdOptions);
app.displayDialogs = DialogModes.NO;//Resets the ALL - you don't want to leave that on.