what happens to the grant I wrote with my PI if I switch institutions
If your name does not explicitly appear in the proposal as an investigator, then the funding, if the grant is awarded, is not committed to you in any way, shape, or form. The PI could in principle take your ideas and use it to fund another student to work on your project!

Unfortunately, most universities will not let grad students serve as PI’s, with the exception of some programs that are specifically aimed at graduate students, such as the Kirschstein Fellowship at the NIH. So you are definitely running the risk of writing your idea up as a proposal and ending up with absolutely nothing to show for it.