I have tried this in two ways in the past. I think of the two, only one will be of use for your objective.
PC Villain in the Group
Create the villain with its player and discuss what their villainous goal actually is. Ensure the player can and will commit to being a villain. Their goal should require the villain to need to be close to or involved with the players to achieve. You will probably want the nature of your villain to be a big revelation at some stage of the campaign, so they need strong hooks to tie them to the heroes, and to tie them to what the heroes are trying to do.
Of course, the heroes will want to achieve a positive outcome in the scenario, while their supposed "friend and fellow hero" is actually trying to ensure a negative outcome. This ensures challenge for each player without necessitating that the players be targetting each other, limiting the sense of mutual dependence, or requiring that the relationship be entirely based on lies.
In truth, the variance between the heroes and the villain might only a slight difference in ideology, the burden of a dark family secret, or the interplay of noble but misguided intentions.
Example:
*Over time the group learns that an ancient prophecy claims a soul-collecting terror from ages past will rise again to plague a small village on the ancestral lands of one of the characters.
As they uncover more and more about the prophecy, they realize that the time will soon arrive. They must act now. They become desperate to discover a way to prevent or guard against the soul-collector.
Throughout this period, the villain is aware that it was their many times great grandmother which unleashed this foul curse on the village in the first place to spare her own children from the ravages of the soul-collector. If the villain chooses to delve deeper into the lore of the family, they will discover much more about the monster than the heroes, including that it was bound by the family to both stop greater depredations and to extract special favors from it. They can, if they have the will, learn how to bind it, and become tempted by what the being will offer for even a little bit of freedom. They will also learn that if the monster is balked it will come for them, their siblings, and other members of that generation within the family and nothing will be able to stop it. Worse, if they reveal the family secret they will be disowned, the monster will take back all the gifts it provided the family, and it will be set loose to kill indiscriminately. To ice the cake, if the villain chooses to master the rites involved, they can gain direct control of the monster and earn their own, very special favors from it.
The heroes will of course be committed to stopping the creature, and their flawed understanding of the situation will enable the villain, if they stick close to the heroes, to monitor progress and to try to redirect it when necessary to prevent success.*
Requirements
This style of scenario best pits character goal versus character goal, but not character versus character explicitly. It does not need to require that the villain receive lots of useful extra knowledge, nor that they go off for extended periods to plot or take care of things off-screen. Moreover, it allows all the players to play toward a goal of uncertain resolution, rather than forcing one of them to be a glorified NPC just there to trick the players. A great scenario will have lots of conflicting emotions on both sides of the group as the course of events plays out.
Key Points
- Everyone plays in the scenario, no ringers or PCNPCs
- Each has a related goal that they may or may not achieve
- once play starts there is no meta-fiddling with the villain's
knowledge or activities
- the heroes may remain focused on ending the threat little knowing
they have a viper in their midst
- the villain has the burden of keeping their secret agenda of foiling
the goal of the heroes without getting caught
At the end, there is a chance for a dramatic conclusion when the duplicity of the villain ultimately comes to light. If the bonds between all the PCs are tight, the heroes may even be swayed to the villain's side...
What you are describing is not a GM PC, it's a normal NPC villain. In the system you're using, building villains using the same character-creation rules as the PCs is also normal. Neither of them makes the villain "your PC".
It's hard to tell why you call this villain "my PC", though:
If you just wanted to be clever and make them use normal character-creation and levelling rules, then that's fine, and it's not unusual. They're not your PC though, they're just an important NPC. Treat them like a disposable pawn like every other NPC.
If you want a character to call your own and put the same care and attention into their levelling-up development, stop. Don't do that in a game you're GMing. If you want the enjoyment of being a player, be a player in someone else's game. Even GMs with years of experience mostly can't pull that off without "playing favourites" with "my PC", and a novice GM is certain to ruin the game trying to have a GM PC. The GM has a job to do, and doesn't have time for "being a player" in their own game.
As the GM, the entire world is your character. Choosing one NPC to be "your character" means they get too much of your attention and the rest of the world and game gets neglected. As a new GM, learn to walk first: learn to run a whole world, learn to build flexible plots that respond to player actions, learn to create memorable characters (even unimportant ones), learn how to pace a session.
If your game revolves entirely around your plans for this one NPC, you've created your own Achilles Heel, and one unexpected turn of the game will undo all your plans. But if you have a whole world that you've been tending to, with loose plans scattered across it, then one villain dying unexpectedly won't wreck the game at all – instead, it will be a moment of triumph your players will have earned through their own skill, and they'll remember that moment and game for years.
Best Answer
First, probably the best way to prevent the party from betraying each other too early is to make sure they need each other alive, up to some point, and they know it. At the very least, the villain player should need the other players alive.
For example: The goal of the campaign is to open the Demon Door and defeat the Demon King before he returns to his full power and fills the world with evil, but the door can only be opened by 4 (or however many people you have in your party) legendary heroes. That way, they can't kill each other before the end of the campaign.
Now, when they fight, you probably want them to be on roughly even ground. I'm going off my D&D 3.5 knowledge here, so it might not quite apply to 5e, but if an encounter is equal to the party in power, it has a CR of 4 higher than the party's level. This assumes a party size of 4. So that could be one character of 4 levels higher than the party, or 4 characters the same level as the party (e.g. literally the same as the party), or your villain and 3 monsters.
For example, when they get past the demon door, the villain is possessed by the Demon King and gains his power (instantly gaining 4 levels; have him make a separate character sheet before hand). This is still in the rest of the party's favor unless there are only 3 of them now, action economy and all. Or, give him control of 3 demons with a CR equal to his level.
So that would be an equal encounter ROUGHLY, as a rule the side with more people at the same CR has an advantage. Now lastly how can we play with the intrigue a bit more? You could have it so that the villain has an advantage if they get to the fight against him without knowing who the villain is, but the party has an advantage if they figure it out ahead of time.
For example, when the party realizes someone will betray them, they can seek out an artifact that will stop the villain from being able to gain his levels or demon allies when they reach the demon king. But, they have to know who the villain is- if they use it on the wrong person, the villain still gets his demon king powers. But if they've guessed who the villain is correctly, they'll have a huge advantage in the final fight. If you're doing this, you might want to make it so that the villain can (for example) gain 5 levels instead of 4, or have 4 demon allies instead of 3 when the party has failed to guess who he is, so he really has an advantage in the fight.
In summary:
How I'd do it is make it so the party all needs each other to enter the final dungeon and can't kill each other ahead of time, the villain gets powered-up to boss-enemy level when they get to the final room of the final dungeon, and the party can stop that from happening but they have to guess who the villain is correctly.