Well, when all you have is a dupehammer, most questions start looking like duplicates. Not that this is a bad thing, mind...
On the one hand, you've done a good thing; you've closed a question which isn't the best quality and is solved more by the user debugging their own code than having us debug it for them, which is in the best interests of all of us. It stopped [more] uninformed answers or "best" guesses at solving this problem, which means there's less noise to filter through to get signal.
On the other hand, you've taken a privilege intended to do one thing - close questions as duplicates - and used it instead to close a question as "unclear what you're asking", or "why isn't this code working?"
While I'm okay with the result, I personally feel that it shouldn't have to come around like this, since someone who sees this later on might disagree with the dupe closing and attempt to apply a better close reason, which would largely undo the work that this particular closure did.
You pose the question of, "Did I do the right thing?" In essence, an unclear question is now closed until the OP can hopefully get more details to prospective answerers to avoid any ambiguity. However, you've had to use a tool that's very narrow in scope (and intentionally narrow in scope) to accomplish it.
You did the right thing in the wrong way. I doubt I'd personally do it, but I don't want to see it reversed in this current state, either.