This internal error message is generated if QuarkXPress, after moving all objects to the base (default) layer, as per the Remove GridTemplate Layers Diary Generation Options settings, cannot reset the z-order of all objects to their relative positions as they were before moving all objects to the base layer.
This message is usually due to unnecessarily complex templates containing too many unnecessary groups of objects. You could try to simplify your grid by removing all groups that are not needed. But, first, check if the resulting output file is OK, as in most cases, a slight z-order shift of a few objects will not jeopardize the overall functionality of the grid.
If this message represents a real problem, please send the script to technical support.