Is my code my intellectual property or the university's? I'm an undergraduate researcher. I wrote a script to solve a problem when I was working on our previous research project. I was unpaid at the time.

Now I am paid for my research and am updating my script (so that it runs better and is more easily accessible to my research group and easier for them to maintain when I leave.)

Who owns my code? Me or the school? Does it matter that I was unpaid (essentially doing the research for fun) at the time I initially wrote the code?

I'm fine with my research group using it in the future, but I want to be able to use it in the future as well when I move onto graduate school.

My current plan is to really build on it and make a really nice suite that would be applicable to both what we're doing now and what I would like to be doing in grad school, but I don't want to do it if I'm going to run into legal hot water.
As noted in the comments, this really depends on university employment policy.  It is further complicated by the fact that you were a student but not an employee when you did the first work, and so different policies might apply.  If you wanted to commercialize the software yourself, you'd probably need to get lawyers involved and everything would likely become complicated and sticky.

Given that your stated goal is to be free to work with the software in the future, however, the easiest path is probably to simply nullify the question by getting the software released under a free and open software license.  This is typically quite easy to do with early-stage academic software, and (de facto) usually just requires consent from your professor.  This is a win-win solution: you and the university both get credit for the software (no matter who owns it, your authorship is never in doubt), and you and everyone else in the world gets to make use of it and improve it, no matter where you may go in the future.