In this situation a relay is "safer" because a relay is an electrically-isolated electrically-controlled switch.
A transistor or MOSFET can be used as a switch in certain applications but when connecting to an unknown circuit, a relay is usually better and more foolproof. ...It would be a bummer if you fried your garage door opener.
Since the Arduino can only put-out 5V at 40mA or less, you generally need a relay driver circuit (made with a transistor or MOSFET). But if you don't want to build it yourself, you can get "relay boards" with a relay and driver built-in.