You can do this with the etoolbox
package, which defines list operations, booleans and string comparison (among other things). The MWE below generates a file stored.txt
where the requirements are stored in order of consecutive runs. For a new run, existing items are numbered in the order of this list and new items are added at the end. Note the comment by @Christian Hupfer.
\documentclass{article}
\usepackage{etoolbox}
\newcommand{\persistent}{} % create initially empty list
\newcounter{Current} % existing position in list
\newcounter{MaxSeq} % highest position in list
\newtoggle{FoundInList} % boolean test if item is found
\newcommand{\cmphandler}[2]{%
\stepcounter{Current}% % increase position in list
\ifstrequal{#1}{#2}% % if the current item is the item to print
{\toggletrue{FoundInList}\listbreak}{}% % then set to found and exit loop
}
% write full list to file after adding items
\newcommand{\writeall}[1]{\write\listfile{\noexpand\listgadd{\noexpand\persistent}{#1}\noexpand\stepcounter{MaxSeq}}}
% print the current item in the document
\newcommand{\printpersistent}[1]{%
\setcounter{Current}{0}%
\togglefalse{FoundInList}%
\forlistloop{\cmphandler{#1}}{\persistent}% % find position in list
\iftoggle{FoundInList}% % if item is found
{\arabic{Current} #1}% % print position and item
{\listgadd{\persistent}{#1}\stepcounter{MaxSeq}\arabic{MaxSeq} #1}% % else add to end of list and print item
\par % start new paragraph
}
\begin{document}
% load existing list if available
\InputIfFileExists{stored.txt}{}{}
% print all items
\printpersistent{alpha $(\alpha)$}
\printpersistent{delta $(\delta)$}
\printpersistent{beta $(\beta)$}
\printpersistent{gamma $(\gamma)$}
% print full list to file
\newwrite\listfile
\openout\listfile=stored.txt
\forlistloop{\writeall}{\persistent}
\closeout\listfile
\end{document}
Result after three runs:
delta
was inserted as 4th item later on then.