With respect to the square brackets —
‘Also, how do I export the results in excel format.’
It might be easiest to save all that to a cell array, then use the writecell function.
However, it might be best to write it line-by-line to a text file, and use the approopriate combination of 'HeaderLines' and other options with respect to reading it (as a table or matrix). Writing it and reading it later are going to be something of a challenge, regardless.