X-Files was one of Fox's first real hour-long shows and they were still in their overall infancy as a network. They were, for all intents and purposes, 4th in line. Expectations were low and the show had some ratings wiggle room. However, they managed to catch lightning in a bottle. Anderson and Duchovny had great chemistry, and frankly there was nothing like the show on any network at the time. It managed to be a ratings hit for Fox. It succeeded in the way that most things in entertainment succeed, a lot of luck to go with everything else.
That said, there's a reason it's known as the Friday Death Slot. X-files is the exception. Nothing has survived there for very long.