Dump Current Incidents to Text File

Good afternoon,

I am hoping to have a script run on a scheduled basis and dump current
active tickets and the number of incidents closed for the current &
previous month to a text file. The file output would look something like:

month, state, value
current, active, 4
current, closed, 10
previous, closed, 8

This file will be consumed by my visualization folks and added to dashboard
along with other metrics from other systems. We use RT for incident
response so each of these would correlate to an open or closed incident the
Security Team is working/has worked on.

I have worked a bit with RT but not tried to pull data out of it and am a
RT novice (RT not scripting). What is the easiest way to do this?

Thank you.