It seems strange that L would have Erin go undercover for that party to rescue Matsuda from the Yotsuba Group after all the effort hed put into making sure Light and Misa didnt know about her involvement (which she screwed up in one swoop several chapters earlier). But remember how Erin got involved in the first place, besides the fact that shed seen the task force arrest Misa: when she was out sightseeing, she managed to bump into Misa and without knowing it, touched her notebook and saw Rem, thereby getting that picture of a monster that only she could see. While Erin may have put it out of her mind until later events when Rem would make her reappearance after Higuchis arrest and death, L never forgot about it. Its possible that he sought her out again after Misa made that mention in one of her videos about shinigami, and ever since taking her into custody, he had used her to try to sniff out the next Kira by making her look for the thing without her ever catching on. The problem was, when Rem appears again, shes attached to a different notebook than the one Erin had touched, thanks to the gambit Light had pulled before offering to be confined that no one else would have any way of knowing about, therefore she wouldnt be able to recognize Rem without touching this new notebook. Either way, it doesnt take much for L to piece things together once Erin breaks down and reveals that Rem was in fact the thing shed seen while sightseeing.
Why wasn't Erin killed even though she walked in on Light and Misa discussing their plans and told L about it? Because even if they knew that she was there and Misa would have been able to get her name using her Eyes, killing her would have irreversibly incriminated them. As someone who isn't a criminal or an investigator neither Kira would normally have a reason to kill someone like her. Theoretically, they shouldn't even know that she's involved in the case. The task force would have never been able to overlook this, especially with the constant surveillance she's kept under even when Light and Misa are granted their freedom. So if they killed her, they would have had to wipe out everyone else too. But only after first getting rid of L, who is currently the main threat. L must have figured this out too, and he exploits it for all it's worth.
Why wouldn't L go trick-or-treating? Because Erin had mentioned inviting Misa along. By this point Misa has regained her powers and re-acquired the Shinigami Eyes. The following chapter it's revealed that at least 16 criminal deaths occurred Halloween night.
Why didn't Misa kill Erin after she'd touched her purse?
Erin wears a Fedora, and according to the rules, the Shinigami Eyes cannot be used to see a person's name and lifespan unless their eyes are visible. Her hat was probably hiding her face. Plus, Misa was in such a hurry to get her purse back and leave, she probably didn't see Erin's reaction to seeing Rem, and since Rem's back was turned, neither had Rem. Misa isn't exactly careful like Light is...
Also, the second time Erin met Misa at the school, why didn't she notice Rem?