I have some details on this problem.
(1) I set up identical Moodle 3.1.2+ installs, one on the old server and one one the new server. On the old server, I can publish/export the gradebooks the way I'd expect to.
On the new server, I get the error message mentioned.
(2) If I publish/export only a portion of the gradebook (it is a large gradebook, with around 250 columns), I succeed with up to about 130 columns. Above that, the error happens. I can choose any 130 grades and it works. The graded items themselves do not seem to be causing the problem.
(3) I suspect the large gradebook is overloading some parameter on the new server, which needs to be enlarged.
Does anybody have a guess as to what that could be? All the obvious settings are identical between the two servers -- especially php.ini in Moodle and on the server itself.
The new server does have opcache installed, which the old, working server does not.