I was running into the same issue. Writing multiple times to the same excel spreadsheet with either writematrix or writecell eventually results in a permission denied error. Some more docu would be great on this issue.
I don't understand how functions can be deployed which cannot repeatedly be called??
I can suggest two workarounds which solved the issue for me:
Either use the windows excel. Be aware that, for me, this resulted in much more execution time than before.
writematrix(header, fullFileName, "Sheet", mirror.serialnumber, "Range", "C1", 'UseExcel', true);
or close all files after a some calls to a write function.
In my case, I have a function writing to a spreadsheet with multiple writematrix calls. A single call of this function works fine, calling the function multiple times on the same sheet resulted in an error. Closing alll files at the end of the function resolved the issue.
In all cases I used the full file name.
Hope this helps someone.