The last question is the easiest. You apply a licence to it because if you don't, the software is unusable. Nobody else will have the right to run, copy, modify, or redistribute it, so nobody will.
As to why you'd put your name on it, I agree that in theory some patent troll could sue you. The thing is, patent trolls exist to make money via lawsuits. It's the only reason they buy patent portfolios, and the only reason they sue based on those portfolios. It's axiomatic in law that you don't sue a paper tiger; the moral satisfaction of getting a judgement in your favour when no money can be collected from the defendant is poor reward for human plaintiffs, and none whatsoever for corporate ones.
Most ordinary free software developers simply aren't worth suing. Only when the projects become successful and widely-adopted, and the code starts being distributed by third-parties, does any kind of any attractive target (ie, a corporate entity with a goodly chunk of VC money in the bank) pop up. For this reason, companies that make distributions have people whose job is to track patents that particular bits of free software might infringe, and keep those bits of free software out of the distro until the patents have expired (full disclosure: I wrote the linked article). As you'll see from the link, some patents are known to have aggressive enforcement: yet even those active enforcers didn't bother to go after the original free software projects.
None of this is a guarantee. Some patent holder could get so angry that your
libfoo infringes on his patent for enabling bars to baz that he decides to sue you (or initially more likely, send a cease-and-desist letter). But history suggests that this doesn't happen much.