Run database queries and dump results to text file