There are many blog posts, guides, code snippets and stackoverflow answers that describe how to create and download a CSV file in PHP.
Anyway none of them helped me the last time I was asked to do that in the context of the configuration panel of a PrestaShop module.