This uses a macro \foocollect
and \NewEnviron
instead of \newenvironment
, the \foocollect
expands the previous \foocollect
versions and then the local \BODY
of the current environment.

\documentclass{article}
\usepackage{lipsum}
\usepackage{environ}
\def\foocollect{}
\NewEnviron{foo}{% Some code here
\xdef\foocollect{\expandafter\unexpanded\expandafter{\foocollect}\par\expandafter\unexpanded\expandafter{\BODY}}%
}[% Some code here
]
\newcommand{\listfoo}{%
\foocollect%
% Some code to list the content of the `foo` environments.
}
\begin{document}
\lipsum[1]
\begin{foo}
\bfseries Foo text 1
\end{foo}
\lipsum[2]
\begin{foo}
\bfseries Foo text 2
\end{foo}
\lipsum[3]
\begin{foo}
\bfseries Foo text 3
\end{foo}
\listfoo
\end{document}
Update with storing to a file instead of memory
\documentclass{article}
\usepackage{lipsum}
\usepackage{environ}
%\usepackage{morewrites}% only if you run out of filehandles
\newwrite\collectedcontentfile
\AtBeginDocument{%
% Automatically open the file at the beginning of the document
\immediate\openout\collectedcontentfile=\jobname.cll
}
\NewEnviron{foo}{% Some code here
\immediate\write\collectedcontentfile{%
\expandafter\unexpanded\expandafter{\BODY}^^J
}%
}[% Some code here
]
\newcommand{\listfoo}{%
%Closing the file
\immediate\closeout\collectedcontentfile%
\InputIfFileExists{\jobname.cll}{}{}
}
\begin{document}
\lipsum[1]
\begin{foo}
\bfseries Foo text 1
\end{foo}
\lipsum[2]
\begin{foo}
\bfseries Foo text 2
\end{foo}
\lipsum[3]
\begin{foo}
\bfseries Foo text 3
\end{foo}
\listfoo
\end{document}
\bf
is a deprecated command. You want\bfseries
...