Looks like your $total_size_of_files_in_dir is accumulating. Reset it at the end of the for loop.
In reply to Re: Dir size by shmem in thread Dir size by larus