Here's a way:
# create the string
text <- paste0(sapply(unique(dat$Animal), function(x) {
subdat <- dat[dat$Animal == x, -1]
subdat[[2]] <- sprintf("%03d", subdat[[2]])
paste0("<", x, ">\n",
paste(capture.output(write.table(subdat, sep = "\t",
quote = FALSE, row.names = FALSE,
col.names = FALSE)), collapse = "\n"),
"\n</", x, ">")
}), collapse = "\n\n")
# write it to a file
write(text, file = "filename.txt")
The resulting file:
<dog>
steak 100
beef 200
poo 001
</dog>
<cat>
milk 020
steak 100
beef 200
</cat>
The columns are tab-delimited.