Fix filename and permission

For Linux but possibly also other platforms.
Check if the fileName isn't empty.
Fix the fileName with adding a / between the dir and the name
Remove dir from fileName before it is set
Set permissions to 666 (rw to all) because of created as root
and no way to tell wich user is better to be used.