It looks like I forgot a + sign in the below line. I don't think it's really a problem however other than sloppy coding. Let me look further.

 Code:
$dir = $home+$folder