Writing with too many system calls
I have a writeOnFile() method with too many fwrite().  ...

A way to reduce fwrite() calls is to simply write all text to a large char buffer[] and then write that once per for (int i = 0; i &lt; global_index; i++) loop.
Use the return vale of snprintf() to speed calculation of next offset.  Use  *printf() features for padding.
for (int i = 0; i &lt; global_index; i++) {
    char buf[N];
    int offset = 0;

    //snprintf(strNumber, 50, &quot;%f&quot;, instants[i]);
    //fwrite(strNumber, 1, strlen(strNumber), out);
    //for (int i = 0; i &lt; strlen(header1) - strlen(strNumber); i++)
    //    fwrite(sp, 1, 1, out);

    //                                           vv---- pad on right
    int len = snprintf(buf+offset, N - offset, &quot;%-*f&quot;, (int) (sizeof header1 - 1), instants[i]);
    assert(len &gt;= 0 &amp;&amp; len &lt; N - offset);
    offset += len;

    //snprintf(strNumber, 50, &quot;%d&quot;, playing[i]);
    //fwrite(strNumber, 1, strlen(strNumber), out);
    //for (int i = 0; i &lt; strlen(header2) - strlen(strNumber); i++)
    //    fwrite(sp, 1, 1, out);

    len = snprintf(buf+offset, N - offset, &quot;%-*d&quot;, (int) (sizeof header2 - 1), playing[i]);
    assert(len &gt;= 0 &amp;&amp; len &lt; N - offset);
    offset += len;

    ....

    fwrite(buf, 1, offset, out);
}


Some other ideas to linearly improve performance.
Why run down string again to find length?
//snprintf(strNumber, 50, &quot;%f&quot;, instants[i]);
//fwrite(strNumber, 1, strlen(strNumber), out);
int len = snprintf(strNumber, 50, &quot;%f&quot;, instants[i]);
fwrite(strNumber, 1, len, out);

No need for strlen() for a constant string
char header1[] = &quot;Instant        &quot;;
// fwrite(header1, 1, strlen(header1), out);
fwrite(header1, 1, sizeof header1 - 1, out);

Questionable &quot;safe:&quot; concerns
sprintf() is certainly faster (or as fast) as snprintf() ....
// snprintf(strNumber, 50, &quot;%d&quot;, playing[i]);
sprintf(strNumber, &quot;%d&quot;, playing[i]);

... yet by some coding standards, better to use snprintf() even though &quot;%d&quot; will not overfill 50 char array.
What is curious about this &quot;safe&quot; code is the lack of checks of fwrite() return, a more likely issue.
    // fwrite(strNumber, 1, strlen(strNumber), out);
    size_t nmemb = strlen(strNumber);
    size_t written = fwrite(strNumber, 1, nmemb, out);
    if (written != nmemb) Handle_Error();


Watch out for unsigned bugs
Consider what happens when strlen(header1) &lt; strlen(strNumber)
for (int i = 0; i &lt; strlen(header1) - strlen(strNumber); i++)

is like
for (int i = 0; i &lt; strlen(header1) + (SIZE_MAX - strlen(strNumber) - 1); i++)

due to unsigned  math wrap around.
Better coded as
for (size_t i = strlen(strNumber); i &lt; strlen(header1); i++)
// or 
for (size_t i = strlen(strNumber); i &lt; sizeof header1 - 1; i++)


Watch out for long &quot;%f&quot;
&quot;%f&quot;  may takes 100s  of characters for large FP values.
Consider &quot;%g&quot;.

Curious that OP's code did not start with fprintf() rather than snprintf()/fwrite().  This is another option.
Conceptually, fprintf() is effectively doing the char buffer[] mentioned above albeit without many fwrite()/fprintf() calls.
Switching to fprintf()  and using the suggested padding format will be sufficient for a first level speed-up.
For me, I do like the idea of writing a line with one I/O call.   It is symmetric with the idea of reading one line on input code with fgets().