It's actually easier (and better) to just use the \label-\ref system. It's easier because you don't have to worry about how to write out to the .aux, and it's better because it writes out to the .aux at the right time so the page references are correct. Here's how to do it:

\documentclass{article} \makeatletter \newcommand{\myLabel}[2]{% \def\@currentlabel{#2}% Update label \label{#1}}% Mark label \makeatother \begin{document} \myLabel{abc}{def}\ref{abc} \par \section{Lord} \subsection{of the} \subsubsection{Rings} \myLabel{Rings}{\thesubsubsection.2}\ref{Rings} \end{document}
Note that the \makeatletter...\makeatother pair has to be outside the macro definition. And updating \@currentlabel is the only thing needed to correctly establish the reference. The .aux file for the above MWE contains:
\relax \newlabel{abc}{{def}{1}} \@writefile{toc}{\contentsline {section}{\numberline {1}Lord}{1}} \@writefile{toc}{\contentsline {subsection}{\numberline {1.1}of the}{1}} \@writefile{toc}{\contentsline {subsubsection}{\numberline {1.1.1}Rings}{1}} \newlabel{Rings}{{1.1.1.2}{1}}