It differs depending on what you mean by "here". When it indicates the location you are doing the action "writing" (e.g. in a room), で is used, and when it refers to the object/place you are writing your name on (e.g. on a document), に is the one.
In the same logic, your first example sentence should be ここでなまえをかいてください when the speaker means the location of action (e.g. in this room) by "here".