I think you are right in that the duplication is coming from the template.
Didn’t know if that was down to how it has been written (by the OP) or if the mixing of TemplateS and TemplateR is somehow corrupting the individual template file.
I only use TemplateR and didn’t know how to advise the OP about using TemplateS at the same time. Useful to have extra input and advice. Much appreciated.