Only write the history stack when called from the darkroom.

Indeed there is nothing to save when called from the lighttable
and actually this will erase current history stack of the
selected images.

Better fix for #9340.