No, in fact save-excursion is the right thing to use. I was debugging something earlier and forgot to put it back. Thanks for the reminder :-)
Here's the latest version, which I think has somewhat more helpful behavior in a couple of corner cases.
(defun copy-and-comment-lines (beg end)
"Insert a copy of the lines in region and comment them.
When transient-mark-mode is enabled, if no region is active then only the
current line is acted upon.
If the region begins or ends in the middle of a line, that entire line is
copied, even if the region is narrowed to the middle of a line.
The copied lines are commented according to mode.
Current position is preserved."
(when (and transient-mark-mode (not (use-region-p)))
(setq beg (line-beginning-position)
end (line-beginning-position 2)))
(setq beg (line-beginning-position))
(unless (= (point) (line-beginning-position))
(setq end (line-beginning-position 2)))
(insert-before-markers (buffer-substring-no-properties beg end))
(comment-region beg end))
;; Don't modify region or display if called as a function.
(when (called-interactively-p 'all)
;; If narrowed, make sure newly commented lines are visible in the
;; narrowed region.
(when (> (point-min) beg)
(narrow-to-region beg (point-max)))
;; Make sure newly commented lines are visible in the window if at the
;; very top.
(unless (pos-visible-in-window-p beg)
(set-window-start (selected-window) beg)))))