Root seems not to have write permission in /opt/dir1/scripts/
. What you do is not what you intend to do ;)
First, you should create the folder to make sure it exist: mkdir -p /tmp/apache
With cp $i /tmp/apache
you copy a file into that directory.
gunzip $i
does not extract the file you just copied, but the original file from the line above. I suggest a more easy way to do this using zgrep. zgrep is like grep but also works on gzipped files. Try this for a start:
#!/bin/bash
# create the folder (-p supreses warnings if the folder exists)
mkdir -p /tmp/apache
# create the output file (empty it, if it exists)
echo "" > /tmp/apache/output.txt
zgrep -i 'Mozilla' /opt/dir1/scripts/access_*.gz >> /tmp/apache/output.txt