From the error message, it seems that the variable "line" is not a text; it contains numbers. You need to cast the variable line as a character to fix the error.
Make the following change in your code and it should work fine:
writeLines(as.character(line), fileout, sep = "\t")