OK...Just reread your question, and realized that it was more in depth than my original reply took into account...sorry bout that...lets try this again.
I will assume that you are storing the user submitted info in a DB(lets call each instance an item), since you want it threaded, and doing that in a text file is a huge headache. Basically, you need each item to have the info, AND a parentID--you can then recurse through all of the records, using the parentID to properly display the items in the proper order. So basically your code would resemble something along the following lines:
function showthreads($itemid){
$query = "SELECT FROM table WHERE itemid=$itemid";
$result=execute the query;
display results;
#now get the children--
$query2="SELECT FROM table WHERE parentid=$itemid"
$result2= execute query2;
for($x=0;$x<count(result2);$x++){
showthreads(result2's itemid);
}