Add ability to save magnet links to file

I use a headless deluge server. I modified your script to support saving the magnet urls to a random file in a  specified directory. I tried not to break the initial use case.

Let me know how I can help