The thing about the pen is that ... it's a pen. Replacing all the parts means that you've got an entirely different pen on your hands than the one you started with.
With humans, we're more than the sum of our physical parts. We have personalities that stick with us throughout our lives, barring some extreme damage to the brain that causes a complete shift in how we act and our memories. I suppose that can lead into a similar question, then: if we lose our memories and gain a completely different persona, are we still the same person we were before?
You are right in saying that it is just a pen, and it is a different pen because you replaced all the parts. But the form or the essence of the pen (what a pen actually is, which in this case would be its function), is still the same. The idea doesn't change, but the pen's material components do.
I like your question. I have discussed it several times over the course of my philosophy undergrad minor, and often found that the answer was that our memories are what gives us our identities, they are what make us out to be who we are, for they help us shape our perspectives about ourselves, our lives, and our surroundings based on whether the memories are good or bad, or neutral. If one were to lose their memory, their physical body may retain the same form, they are still human, but they may not still be Brad, or Angela, or Michael... for the personality of the person, and the mind that holds the memories allows to be said person and make decisions based on said person's personality and morals. Memories enforce morals, as memories enforce opinions, because opinions come from experience, or knowledge and thus allows us to draw our opinions on said universal morals (we take a side and choose who to be based on what morals we choose to acknowledge as important). So having no memories causes us to lose our opinions, our pre-conceived thoughts, and all notions of how to act in certain situations and thus we would have to take on a new persona, and become a new person.
But I think there needs to be a distinction made. If we are to lose our memories but gain a new persona, then whatever that persona is, we become, or we change into. Values change as memories are obtained, and perspectives reflect our ever growing understanding of situations that play key roles in deciding who we are. I think though, that in-so-long as there are trace memories of who we once were, we will always have a part of our old self, even if that old self is not in action (if that makes sense), which does give way to the possibility of reverting back to ones old self, if enough trace memory can be recovered.
However, if one were to lose their memory and not gain a new persona, not learn anything new, not create new opinions nor have any new perspectives, but rather be in a place of utter nothingness, then we have a different problem on our hands. Do we classify a person like this as the same person as before? No, not normally, so then why would we classify someone who takes on a totally new persona as the same person as they were beforehand? We wouldn't.
Unless that new persona was faked, then of course the memories would still all be there, and that person would be the same but with just a veiled front.
I think my question here would be, would that person who has lost their memory and must create a new persona, would they go down a similar path as to who they were prior, or would they take on completely different aspects? How much of personality is hardwired and how much of it depends on our learning, surroundings and memories? I think our person has everything to do with our knowledge, our memories and our surroundings and how we know how to act within those surrounding situations.
I have a lot more to say on this topic, but alas it is 5am and I probably should let me brain rest. I would love to hear all your thoughts though, because mine might just change!