This is Ebert's "Law of Economy of Characters" - "Movie budgets make it impossible for any film to contain unnecessary characters. Therefore, all characters in a movie are necessary to the story—even those who do not seem to be."
In particular if it's a serialized piece, like episodic television, and you meet "an old friend" of a major protagonist character (or in Star Trek a commissioned officer on the finitely-staffed ship) they've never mentioned before, the new character often literally exists to be a source of adversity and loss for the major character.