How come when I open the file read-write it wipes it out?

Because you're using something like

    open(FH, "+> /path/name");	# WRONG

which truncates the file and then gives you read-write access. Whoops. You should instead use this:

    open(FH, "+< /path/name");	# open for update

Which will fail if the file doesn't exist. If this is an issue, try:

    sysopen(FH, "/path/name", O_RDWR|O_CREAT, 0644);

Error checking is left as an exercise for the reader.

    sysopen(FH, "/path/name", O_RDWR|O_CREAT, 0644);