>>> tfile = open("text.txt", 'w')
| write(str) -> None. Write string str to file.
| Note that due to buffering, flush() or close() may be needed before
| the file on disk reflects the data written.
As you see write takes string as an argument,so if you try to put in an integer you get an error.
That error message is pretty clear first part TypeError: must be string,should be a good hint.
Beat_Slayer has the easy soultion to this.