Custom CSV exporter – Cannot modify header information – headers

You can’t use header after content has been sent to the browser, headers were already sent. Your code runs after part of the admin page it appears on has already been output to the browser. You can solve this by moving your output code into a function hooked to something that runs earlier, like admin_init, or use the admin_post action.