I can't see any smoking guns in your code above that would make it fail, but in your similar question to the Excel::Writer::XLSX mailing group, you mentioned using the Dojo javascript library to trigger the download (using Ajax/POST I think).
I've encountered similar issues when trying to initiate binary downloads by POSTing with jQuery Ajax functions, so it's worth checking your Dojo code and if necessary using one of the workarounds for initiating downloads via XHR/Ajax.
I've done this in the past myself using a two-step Ajax conversation, like this:
- Browser requests (via Ajax/XHR) that Excel file is built on the server, sending any parameters required via GET/POST, as usual.
- Server responds with Json/XML indicating success/failure, and including a URL to where the new binary file can be downloaded, in its response.
- Client side code creates a hidden (or out of view) iframe, setting its source as the URL indicated in step 2.
By setting a custom Content-Type, you can hint to the browser that you want a download prompt.