The only way to write column-by-column to a text file is to arrange the code so that at each step, it reads the existing contents of the lines and writes out the extended lines to a new file.
It has been decades since MATLAB was supported on an operating system that supported appending to an existing line without rewriting the entire file -- and when MATLAB was supported on that operating system, MATLAB used the I/O subsystem that did not support that option. So hypothetically decades ago MATLAB could have supported doing that, on that one operating system, but did not. In all other cases, it has been literally impossible on the operating systems MATLAB has ever run on.
All file systems ever supported by MS Windows, and all filesystems ever supported by Apple, or Unix, treat files as a stream of bytes, with particular characters in the stream being used to mark the end of lines. Historically MS Windows used to use Carriage Return followed by Linefeed (\r\n) as the end of line characters, and old enough versions of Apple's file system used separation between paragraphs instead of between lines; all modern versions of MS Windows and Apple and Linux use linefeed as the line seperator.
None of the supported operating system has any inherent support for "lines" . No support for inserting lines or deleting lines, or positioning directly to a line, or appending more to a line. The only support those operating systems have is for positioning by byte offset, and for reading or writing bytes (and for truncating files). Adding more to an existing line in all of those operating systems requires re-writing the entire rest of the file.
TL;DR: Don't do that.
Transpose your data so that the known data at any time becomes a row -- and then adding more content just becomes a matter of adding more rows to the file.
Or keep everything in memory and write it all out at the end.
Or read in the file and write out the entire new content, such as by using readmatrix() or readcell() and writematrix() or writecell() -- this will be inefficient and is not recommended, but at least it will take care of the overhead so you do not need to handle it yourself.
If the problem is just that you have multiple columns in memory and you do not know how to write them all out at one time, then we can work with you on that. For example in a case like your example you would use cell2mat() or horzcat() to create a rectangular numeric matrix that could be written out all at one time. Formats can be constructed dynamically:
ncol = size(DataToWrite, 2);
fmt = [repmat('%d ', 1, ncol-1), '%d\r\n'];
fprintf(fid, fmt, DataToWrite.');