I have been doing part-time unpaid research at a prominent medical institution. While here I created an app at the request of the department head to be distributed by the institution. This program is unrelated to the work I agreed to come on board to take part in, though it does concern a project that they have been working on for many years. This institution is now requesting I recognize that the copyright belongs to them. I did not use any of their resources to create it, was not compensated for it and designed and built the program with little input. I don't mind giving them the technology, but am worried that I won't be recognized as its creator, and that the copyright can be used to claim ownership rights to my future projects, since I frequently recycle code that I've written. On the other hand, I need a reference and don't want to strain any relationships. Any thoughts on how to proceed is welcome.
If you are an employee hired to program, your employer holds the copyright, as a "work for hire". So the main questions are, are you an employee, and is this work done in the scope of your employment? The fact that you did not receive a salary isn't entirely dispositive – I take it this was some sort of internship, where you receive academic credit. Under that premise, they might argue that you were an employee (but they might lose that argument in court). The other issue, whether this was done "on the job" versus "during the time period when you had an affiliation" is not something that can be judged from a legal perspective. They will have a certain position about what you were doing, which you may or may not agree with, so it depends on how compelling your argument is vs. their argument that it was work-related. Since the scope of one's "employment" is not narrowly defined by some initial agreement (it can change), the fact that you did this "at the request of the department head to be distributed by the institution" indicates that it wasn't something unrelated to the job, which you did as a hobby. So on the face of it, it looks that this is indeed within the scope of the job.
There is a separate and distinct possibility, that one of the forms you signed actually signed away your rights (which would moot the question about you benig an employee). It is not at all uncommon for affiliation agreements (intern, employee, adjunct member, independent contractor) to include a clause assigning the institution the rights to your IP.
You are correct that there is a potential for them to interfere with future programming projects of yours. If they in fact own the source code, then they own all of the sub-bits of the code. Copyright protects the means of expression, but not the underlying facts. What is unknown (in law) is where that dividing line is software. It would not overcome copyright protection to simply replace all of the variable names (e.g. "item_count" → "count_of_items"), and cosmetically reorganizing code a also doesn't get rid of copyright protection. However, variable names and structure of code often (ideally?) follows from the nature of what the program does, so necessarily (to take an example), all bubble sort programs resemble all other bubble sort programs to the point that one might accuse an author of infringement. It's an interesting and not clearly answered question, how similar two functionally identical pieces of code can be without there being infringement.
Again, since copyright protects expression and not ideas, if in the course of writing a program you discover a clever algorithm for doing something (rather than dividing by the nth power of 2, shift right n), that knowledge is not protected by copyright, and it is to be expected that if you learn how to solve a problem once, you can re-invent the solution again (and it will strongly resemble the earlier solution). This murky copyright situation means that writing any new code in a somewhat overlapping area is a bit risky, since there is a high probability that any new code would have the level of substantial similarity that constitutes evidence of infringement.
There is no reliable way to find out whether they would succeed in an infringement suit, other than to get sued and see what happens. Consulting an attorney who specializes in software copyright would not be a bad idea.