How do I programmatically export all webform submissions into a single csv? (multiple webforms)
As per your comment that you are interested in "an alternative to creating such CSV file programmatically": have a look at the Forena module (without using Views. Forena can do exactly what you're asking for (so no need for "programmatically").

As an example, create a custom "data block" (which is just an SQL statement) that fits your needs, to retrieve the webform data that you're interested in. Here is a (basic) example that I sometimes use for some testing:

SELECT s.nid AS node, s.sid AS submission, d.cid AS component, d.data AS fieldvalue
FROM {webform_submissions} s JOIN {webform_submitted_data} d ON s.sid=d.sid 
WHERE d.cid=3 AND s.nid=5
ORDER BY s.sid ASC


Then create a Forena "report" that uses this data block, and make sure that within "document types" you enable the "CSV" option. Here is the (basic) layout of such report to illustrate the idea:

&lt;body&gt;
&lt;div id="webform_submissions_data_block" class="FrxTable" frx:block="drupal_cust/webform_submissions_data"&gt;
    &lt;table&gt;
      &lt;thead&gt;
        &lt;tr&gt;
          &lt;th&gt;node&lt;/th&gt;
          &lt;th&gt;submission&lt;/th&gt;
          &lt;th&gt;component&lt;/th&gt;
          &lt;th&gt;fieldvalue&lt;/th&gt;
        &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
        &lt;tr id="webform_submissions_data" frx:foreach="*"&gt;
          &lt;td&gt;{node}&lt;/td&gt;
          &lt;td&gt;{submission}&lt;/td&gt;
          &lt;td&gt;{component}&lt;/td&gt;
          &lt;td&gt;{fieldvalue}&lt;/td&gt;&lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/body&gt;


After you saved the report and browse it, you'll have a "CSV"-hyperlink (upper right of the report). Just use that link and ... voilà, there is your CSV file (in this case with 4 columns, since that is what in my (basic) report I asked for.

If this makes sense, head of to the Community documentation of Forena to get you going (which includes pointers to video tutorials). Or use the documentation that comes with Forena.

Of course, building the appropriate SQL statement to perfectly fit your needs is going to be crucial. But apart from that, it's just basic usage of Forena.

Disclosure: I'm a co-maintainer of Forena.