One way to write the warnings to a text file is using the "evalc" function. You can use the command as follows.
logs=evalc("sim(load_system('model.slx'));")
This command would capture the warnings and errors into "logs" which is of type 'char'. Then the contents of 'log' can be written to a '.txt' file. You can utilize the "evalc" function and apply it according to your requirements.
The output of the above command would look as follows.

For more information about the "evalc" function, please run the following in the command window.
doc evalc
Hope this helps!