Answering your question: here is the basic function for that task. Make sure to add checks of whether file exists, not locked, etc. But take a look at the solution provided by John Coleman as it may be a better solution for your task.
Public Function WritetoTXT (Byval Text as String, byval FilePath as String)
Dim TextFile As Long
TextFile = FreeFile
Open Path For Append As TextFile
Print #TextFile, Text
Close TextFile
End Function
In your code:
Sub xx()
Dim i As Long
Rnd -1
For i = 1 To 20000
WritetoTXT Rnd, "your file path here"
Next
End Sub
Edit:
As pointed out in comments to decrease overhead you can combine your code to the following:
Sub xx()
Dim i As Long
Rnd -1
Dim TextFile As Long
TextFile = FreeFile
Open "your file path here" For Append As TextFile
For i = 1 To 20000
Print #TextFile, Rnd
Next
Close TextFile
End Sub