refactor URL fetching

Extracted similar code into a utility function and updated to use
File::Fetch instead of shelling out to curl.