Some functions return the template file as an R object to then be written out later in a higher level function; others write the lines to a file before exiting.
Make this approach consistent where all functions either return an R object or write the lines to a file - this will improve maintainability for developers. To minimize the number of times writing to file, it probably makes sense to return to an R object until the very end of the wrapper function.