exec master..xp_cmdshell
Try something like this:

Declare @Name varchar(30) = 'Bob'
Declare @DBname sysname = 'TestDb'
Declare @Cmd varchar(4000)
set @Cmd = 'echo ' + 'alter login ' + QUOTENAME(@Name) + ' with default_database = ' + QUOTENAME(@DBname) + ' &gt;&gt; C:\test\test_script.txt'
print @Cmd
exec master..xp_cmdshell @cmd