Character Analysis
Dobby is one of the first magical creatures that we meet in this film series. He says he's trying to help Harry (if you can call it that), but he's also showing us a different side of wizard bigotries and prejudices.
It's really bad luck for Dobby that he happens to enslaved to one of the cruelest wizarding families out there—the Malfoys. But that also means this house-elf is privy to Lucius Malfoy's plan to bring chaos to Hogwarts this school year. So why would Dobby decide to help Harry even though he's risking his own safety?
Dobby sees Harry as a figure of liberation:
DOBBY: Dobby remembers how it was before Harry Potter triumphed over He-Who-Must-Not-Be-Named. We house-elves were treated like vermin, sir. Of course, Dobby is still treated like vermin.
Sure, things didn't get better for Dobby, but he remembers what life was like when bigoted pure-blood families like the Malfoys were living the high life with Voldemort. They were free to spew their vile hatred in public and discriminate against Muggles and other magical creatures because Voldemort was large and in charge. Harry changed all that.
Now, Dobby can't bear to see him hurt. Or for things to go back to the way they were.
So, yes, Dobby is an enslaved creature, but he makes choices, too. He doesn't obey his masters. He betrays their plans and tries to help Harry Potter. Yeah, the help comes in the form of cakes smashed on people's head and bludgers that break Harry's arm, but it's still help.
That's why Harry has to try to help Dobby in return by tricking Lucius Malfoy into freeing Dobby:
HARRY POTTER: Open it.
DOBBY: Master has given Dobby a sock.
LUCIUS MALFOY: What? I didn't give...
DOBBY: Master has presented Dobby with clothes. Dobby is free.
In the end, this is also a big fat comeuppance to the Malfoy family. It's also a thank you to Dobby for his work. At the time, Harry didn't see what Dobby was trying to do, but once he understands Lucius Malfoy's whole role in this saga, he gets that Dobby had his best interest at heart.
But yeah, Dobby might want to lay off the saving Harry's life for a while.