create outputs from other command outputs

hi friends,

The code:

i=1
while [ i -le 50 ] 
do
filename=`/usr/bin/ls -l| awk '{ print $9}'`
echo $filename>>summary.csv
#Gives the name of the file stored at column 9
count=`wc -l $filename | awk '{print $1}'`
echo $count>>summary.csv
#Gives just the count of lines of file "filename"
i=`expr $i + 1`
done

It gives the output like:

filename1.txt#filename
123#count
filename2.txt
234
filename3.txt
567
...
...

But i want the output as

filename1.txt 123
filename2.txt 234
filename3.txt 567

I want to see the output as .csv file, so the columns shud be separated by comma(,).

I think I have to use awk, but dont knw how to use it to get the desired result.

Any help is appreciated.
Best Regards,
Raj

echo "$filename,$count"