in reply to table capture

This is not an answer to your question, but it would be easier to read your code, if you had named your filehandle OUTFILE