hello guys!
I'm newbie in linux bash scripting. Recently taking class Unix/Linux OS's where our instructor started from bash scripting. On the week 2 we already had to learn loops, that just to show how fast he was going through the course. And of course, majority of students got no clue what they do, including present party. I have to finish my last assignment on bash scripting, all class copied scripts letter by letter from the "board" when our instructor was running scripts for this particular assignment, but it doesn't work

.
Would you please take a look at the scripts and tell me what is wrong and what needs to be changed?
The goal of this script is to display user's directories and files in those directories.But instead, that gives me directories of the whole system, all it's files and then at the end of it display users.
Thank you in advance.
Stokil.
Here is my code:
#!/bin/bash
# Name: userreport
# By: Stokil
# Date: 6/4/2014
# Purpose: report of all users on system
########################################
clear
x=500
while [ $x -lt 510 ]
do
user=`grep ":x:$x:" /etc/passwd | cut -f1 -d:`
echo "#####################################"
echo "$user"
echo "#####################################"
echo " "
echo "Home Directory"
ls -ld `grep "$user" /etc/passwd | cut -f6 -d":"`
echo " "
echo "Estimate Directory Size"
echo "======================="
du -h -s /home/$user | cut -f6 -d":" | cut -f1 -d"/"
echo " "
echo "Display the User information"
echo "============================"
grep "$user" /etc/passwd
echo " "
echo "Shadow file"
echo "==========="
grep "$user" /etc/shadow | cut -f2 -d":"
echo " "
echo "Groups"
echo "======"
grep "$user" /etc/group | cut -f1 -d":"
echo " "
echo "Last Login"
echo "===="
last $user
echo "ls"
tree -d `grep "$user" /etc/passwd |cut -f6 -d":"`
echo "============================"
echo " "
let x=$x+1
done