This is a common problem when dealing with float captions. For example, here's the definition of \@makecaption which is called by \caption (taken from article.cls):
\long\def\@makecaption#1#2{%
\vskip\abovecaptionskip
\sbox\@tempboxa{#1: #2}%
\ifdim \wd\@tempboxa >\hsize
#1: #2\par
\else
\global \@minipagefalse
\hb@xt@\hsize{\hfil\box\@tempboxa\hfil}%
\fi
\vskip\belowcaptionskip}
The caption is set inside a box \@tempboxa, after which its tested for horizontal width. If it fits, then the original box \@tempboxa is set, otherwise it is re-evaluated. The re-evaluation is performed to switch from centred (the default) to paragraph-style alignment of the caption. So, any \label or counter-related entries should be used with caution (especially if there's a contents for the floats created as well). Here's a small example:

\documentclass{article}
\newcounter{myitem}
\newcommand{\mynewitem}{\addtocounter{myitem}{1}I-\themyitem}
\begin{document}
\begin{figure}[ht]
\centering\rule{150pt}{\baselineskip}
\caption{This is \mynewitem.}
\end{figure}
\begin{figure}[ht]
\centering\rule{150pt}{\baselineskip}
\caption{This is \mynewitem\ together with a lengthy caption that stretches more than one line.}
\end{figure}
\end{document}
Resolutions to these problems are sometimes provided by manual work-around (which may vary on a case-by-case basis), or perhaps a package. Most solutions are provided by going back to the source and trying to understand the root of the problem, which invariably provide hints to possible work-arounds.
On a side-note. An interesting example of TeX's capability to be different from a programming language is presenting in David's answer to How do you swap the commands for two symbols?, suggesting that it's not always necessary to use a intermediate variable.
\edefor\sboxbe used to eliminate the multiple side effects? See my revised question. – Richard Hansen Apr 08 '12 at 00:13