Last.fm provides data feeds of what you've been listening to recently. But they don't give you a feed for the full list of things you've ever listened to. So I wrote a shell script (a bash script) which should run on Mac/Linux, to archive the XML feed data for me:
To archive the data regularly, you need to set this up to run often, e.g. using cron.