Choose from list apple script service execution from Safari opens Firefox to display the dialog with list
Firefox is likely opening because the script includes:
tell application &quot;firefox&quot;
    …
end tell

Based on your description, these lines require AppleScript to launch Firefox to determine if the script is correct – even if the involved lines are never run. Firefox needs to be launched for AppleScript to obtain the application's scripting language support.
The other browsers implement AppleScript using a more modern approach. They provide their language support through an embedded Scripting Definition file (SDEF) within the application bundle.
open a URL on macOS
You can avoid this behaviour by using the macOS open command line tool and passing the desired browser's bundle identifier with the URL to open.
This removes the need to write browser specific sections of AppleScript.
Be sure to quote the arguments:
try
    set myURL to &quot;https://duckduckgo.com/?q=&quot; &amp; &quot;42&quot;
    set bundleID to &quot;com.apple.safari&quot;
    do shell script &quot;/usr/bin/open -b &quot; &amp; quoted form of bundleID &amp; &quot; &quot; &amp; quoted form of myURL
on error (e)
    display dialog e
end try

Calling open without a bundle ID will open the URL in the default browser.
Open URL with Safari
 /usr/bin/open -b com.apple.Safari 'https://dssw.co.uk'

Open URL with Chrome
 /usr/bin/open -b com.google.chrome 'https://miln.eu/apps'

Open URL with Firefox
 /usr/bin/open -b org.mozilla.firefox 'https://indie.miln.eu'

| and Error Checking
You could surround the application names with | to defer script error checking from compile time to runtime. See user3439894's answer for this approach.