how to avoid the "An INSERT EXEC statement cannot be nested" exception on this situation?
The source code for Aaron's sp_foreachdb contains the following line:

INSERT #x EXEC sp_executesql @sql;

According to your error message: 


  An INSERT EXEC statement cannot be nested.


So code like that below will not be valid as it is nesting INSERT xxx EXEC xxx code.

INSERT @temp
exec sp_msforeachdb  @command1='use ?; Exec sp_helpfile;'