In the wild clownfish live in the tentacles of anemones. Anemones tentacles can sting fish, similar to a jellyfish but less intense, but clownfish have developed a method of becoming resistant to that sting.
Anyway the clown is 'hosted' by the anemone, one animal being the home for another animal is called hosting. Unlike many fish that swim all over the reef, once a clownfish has found an anemone to live in it will stay there. In an aquarium there is usually no anemone so the clownfish simply finds the closest thing, in its mind anyway, to an anemone. Why is this 'hosting' behaviour so strong in clownfish, well basically since the anemone can sting, the clownfish is safe from predators within the tentacles. So the need for a clownfish to be hosted by something is a survival instinct. In the aquarium environment clownfish do perfectly fine without an anemone because there aren't any predators in an aquarium.
The relationship seems to only benefit the clownfish but studies have shown that in the wild an anemone with clownfish will do better than an anemone without clownfish. It is a symbiotic relationship, both animals benefit equally.