in reply to Linux su twice

Seconding haukex. You see it as a sequence of commands, but in fact they are nested. You could try something like
system('echo "echo /path/to/file | su - newuser" | sudo su');