in reply to If Condition causes totally blank Output File/Issue in Writing to Output

Welcome to Perl and the Monastery, hghosh!

it will return a completely empty file

If you don't have a use autodie; at the top of the script, then you are not checking for errors in creating the file. The typical way to do this would be e.g. open my $fh, '>', $filename or die "$filename: $!";. Other than that, based on the code you've shown, the only other reason the first piece of code would not produce any output would be that the loops don't run because %chrsize has no entries or all its values are less than 0 - you can check this by using a tool like Data::Dumper to look at the hash (see also the Basic debugging checklist). Also, just to be safe: are you doing a close OUT; at the appropriate time?

wouldn't Perl automatically set "non-existent" keys to zero/undefined?

When attempting to access a hash key that does not exist, Perl will return undef. Therefore the two pieces of code are not equivalent: the first sets $piRNA{$chr}{$index} to 0 if there was previously no key $index, and then prints the line unconditionally, while the second piece of code only prints the output line if the key $index exists in the hash %{ $piRNA{$chr} }. In general:

If I get rid of the if statement ... It will return the $chr and $index formatted correctly, but will not print the last value.

Sounds to me like $piRNA{$chr}{$index} might be undef or "", which you can see with the aforementioned Data::Dumper, and also, if it's undef you should be seeing warnings about uninitialized values (one of the reasons Use strict and warnings is a best practice). However, if I understand your description correctly, this still doesn't explain the empty output file.

If you could use a tool like Data::Dumper or Data::Dump to get the contents of %chrsize, then you could use this to build a Short, Self-Contained, Correct Example - a short piece of code that we can run to reproduce the problem on our end.

Update 2019-08-17: Updated the link to "Truth and Falsehood".